I’ve started using angular in my express generated projects and i’m loving it. Recently I implemented angular routing into one of my test projects and I’m wondering what the advantages and disadvantages are to using angular routing over pure express/node routing (e.g. are there technical issues with this way, or maybe SEO, or is it totally unnecessary).
FYI on my setup: I have express rendering the main index template as well as routing all request (a catch all) to the main index template and then I’m using angular to route to partial templates from within the main index template
2
Answers
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.
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..)