Nikolay Melnikov Nikolay Melnikov - 1 month ago 10
AngularJS Question

ui-router returns: "Cannot GET /page"

I am using

ui-router
, and have a
profile
state that looks as follows:

.state('profile', {
url: "/profile",
templateUrl: "views/profile.html",
controller: 'ProfileCtrl',
resolve: {
currentUser: function(gamAuth){
return gamAuth.checkCurrentUser(config.userRol.user)
}
}


When I try to reload/refresh the page I get the following message:

Cannot GET /profile


The problem does not occur when I reload my 'landing page' at:
http://localhost:9000/
, which has the following state in
$stateProvider
:

.state('home', {
url: "/",
[...]
})


I am using:
$locationProvider.html5Mode(true);


I tried providing absolute URL as suggested in the Decision Tree here

I also tried a number of suggestions found online, the most popular being something along these lines (placing it in the
app.run()
section):

$state.transitionTo($state.current, $stateParams, {
reload: true,
inherit: false,
notify: true
});


All approaches were tested with and without the
<base href="/">
tag being present in the
<head>
of my
index.html
.
Thank you for your time.

Answer

you need to enable html5mode to true if you want to use your url without '#' prefix.

Also you need to add your modRewrtie in as mentioned here

Prerequisite:

npm install --save-dev connect-modrewrite