Note. This question can also be read:
How to bookmark harmless client side mvc frameworks in Java.
I am moving on to an angular application using hashtags to html5mode . I have successfully installed
$locationProvider.html5Mode(true);
And all the links from the landing page (index.html) are working fine.
The problem is that if partial URLs are referenced directly, I get 404, of course, since the definitions of the server endpoints are not related to client-specific routes.
Thus, without HTML5 we get non-SEO friendly hashbangs, but with it we can’t bookmark anything except the landing page (the page that angular loads).
Why does this work if you first request the default landing page (index.html), i.e. htpp: //mydomain.com/:
- The browser requests index.html from the server
- The server returns index.html and the browser loads the angular framework
- Changes to the URL are sent to the client router and the corresponding partial / s are downloaded.
Why this does not work if (i.e.) http://mydomain.com/foo is requested directly from the browser:
- The browser requests mydomain / foo from the server.
- Resource does not exist
- Server returns 404
Something is missing in this story, I just don't know what. Here are just two answers that I see ...
- This is by design. How it works? Users should always land on the MVC platform boot page (usually index.html) and then navigate from there. This is not ideal, because the state cannot be saved, and there is no possibility of bookmarking ... not to mention a workaround.
- Server solution. . Does this work with a server side trick? For example, for all requests, return index.html and immediately call the router with additional context. If so, it contradicts the object that AngularJS is completely client-side and seems to be hacked.
Robert Christian Jul 15 '13 at 4:35 2013-07-15 04:35
source share