MEAN stack: angular routing vs express routing [closed] MEAN stack: angular routing vs express routing [closed] express express

MEAN stack: angular routing vs express routing [closed]


With the mean stack (mongo, express, angular) you will have routing at both ends.

Express will serve your static index.html and css/js/images and your api, and angular will interact with the api to get data from mongo.

Routing with express will primarily be done for the API, and routing in angular will be done to handle the front-end of your application. Express will not return any html other than the index.html and any template partials that you have written for angular, however even that can be eliminated by compiling all of the templates directly into your js files using a build-tool such as gulp/grunt.


It certainly is possible to go 100% to one side or the other, however, it's impractical because you'll end up inefficiently using one side or the other. For example, if you did all of your routing with express and used angular on each individual page, you would be ignoring all of the single page app functionality and routing of angularjs, leaving it's only purpose being building the page which could probably be done more effectively with express and jade (or any other templating engine.) It isn't really possible to go in the other direction and do all of your routing with angular because angular requires an api to get data from, unless you include all of the data up front inline in the html, which i'm sure you'll agree is a bad idea. (it also eliminates mongo at that point..)


They are solving two different problems. Angular routing (ui-router) is client-side - loading the correct ui-views. Express routing is server-side - the REST APIs you are exposing.