There is an already written web application, I want to rewrite the entire front on an angular. I decided to use Angular 2 in order to practice now and when the stable version is released to have some kind of development experience on it. The first thing I encountered is routing, when we go to the application http://mybestapp.com/ index.html page loads, which loads the anngular itself. When we go somewhere from the main page, for example, click on the /getUser/123 link, the server gives json and we draw the data in the browser. But, if we immediately follow the link http://mybestapp.com/getUser/123 in a new window, we will get just a json string (this is normal server behavior in response to such a get request). Of the ways to get out of this situation, I have come up with only one yet - to look in the getUser controller on the server (and in general in all controllers) whether the x-requested-with:XMLHttpRequest header was transmitted, and if not, then redirect the user to the main page ( http://mybestapp.com/ ), or rather not even redirect, but simply, stupidly take and give him the content of the main page, but at the same time stay on /getUser/123 . But if x-requested-with was submitted, then we will give json. Here you should also note that there are all sorts of pages 404 and other errors.
Please tell me if my approach is correct (it seems to me that there is not), and how to solve this problem correctly?
http://mybestapp.com/getUser/123- sanu0074api.mybestapp.com/getUser/123ormybestapp.com/api/getUser/123. It will be two independent applications - api sends the data, and the angular application accepts data from the api, and already goes through its routing, the routing of the angular will in no way be in contact with the backend routing. - Moonvvell pm