Search code examples
angularjslocation-provider

Angular js with MVC: locationProvider.html5Mode(true) Links Does Not Work, becuse it want to get controller and action from Server


When using angular js routing by default add # after end of location link, and after # any other is the compiled by angular js,
if I want to not show # I can use locationProvider.html5Mode(true)
after route process for example my links in location convert from
http://example.com/#Name to http://example.com/Name now if I create a link using <a href='/name'>test</a> it is works. but when I use http://example.com/Name in address bar and enter, it is not works, and I get error about not found controller named Name controller


Solution

  • If you directly type the url in the browser, it makes a server request. In HTML 5 mode depending upon the server technology you would have to do url rewrite. This is what the documentation on location https://code.angularjs.org/1.2.15/docs/guide/$location has to say.

    Server side

    Using this mode requires URL rewriting on server side, basically you have to rewrite all your links to entry point of your application (e.g. index.html)