atse
atse

Reputation: 3

Serving pages, AngularJS vs Node JS

So I'm learning how to develop a web using angular and node JS and I am confused as to where to decide where acquire the URLs for links. I have been reading around stack overflow as well as random tutorials on both angular and node, and most of them just explain the route handler (which I have figured out now). Generally, they suggest that angular should handle all page routing and so I assume that they're also supposed to handle URL generation. But I read somewhere that the web server(node?) should be generating the URL's and that angular should only be implementing route handling given the URLs. I have no clue how I should be doing it (I want to do it right the first time so I don't end up refactoring a lot of code) and I am quite confused about how to go about generating the URLs that I need. Any clarification would be greatly appreciated. Thanks in advance!

Upvotes: 0

Views: 196

Answers (2)

Jonathan M. Hethey
Jonathan M. Hethey

Reputation: 714

You'll need both anyways, so don't worry about doing too much work. The question is HOW you do it and what your app is like. The parts that are public or should be accessed by search engines, should probably be routed by both node and angular.

If you have a part of the site that is more like a web application behind a login, you can in some cases rely on letting angular do the routing work (mostly) you still need endpoints in your node.js routes that give you back the data (probably JSON).

TLDR: public: both, HTML from node private: angular, JSON from node

Upvotes: 0

Dave Walker
Dave Walker

Reputation: 3523

For a Single Page App (Angulars bread and butter) it's quite common to have a single server side route handler that will serve the exact same content regardless of what page the user lands on. At that point Angular can take over and work out what controller/view is required (via route handler) and show it there.

Corroborating answer - not in node sorry - How to use ASP.NET MVC and AngularJS routing?

Now, when I navigate to http://www.example.com/Application1/view[x] it routes to the Application1 MVC controller, Index action, and then Angularjs takes over routes to the different views, all while having the HTML5 routing construct in the URL.

Upvotes: 2

Related Questions