Throw cannot get error after including html5Mode in AngularJS

I am using UI-Router for routes / states in my application and urls have "#", so to remove this I used $locationProvider

like -

function configState($stateProvider, $urlRouterProvider, $locationProvider) {

    $locationProvider.html5Mode(true);

      

Added ngRoute

depending on the module and added <base href="/" >

to my index.html.

The problem is -

If I use it like a normal app, like in the same tab, and go to a different state, it works BUT when I paste the url in another tab and click, enter it throw Cannot GET /app_views/contacts

url like -http://localhost:9000/app_views/contacts

Though with a hash in the url, it works both ways.

+3


source to share


1 answer


You are likely to receive this error because your server is not configured correctly. In other words, when you manually enter it /app_views/contacts

, it will make a server request for that page. For it to work properly, you need to configure the server to route all traffic to the page index.html

in order for Angular to capture and display the correct view correctly.



Here is the linked post Page Reloading gives wrong GET request with HTML5 mode in AngularJS format

+2


source







All Articles