Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 368
Nikolay Melnikov Avatar asked Nov 13 '14 08:11

Nikolay Melnikov


2 Answers

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
like image 140
CrazyGeek Avatar answered Oct 12 '22 02:10

CrazyGeek


When you have html5Mode enabled, the # character will no longer be used in your urls. The # symbol is useful because it requires no server side configuration. Without #, the url looks much nicer, but it also requires server side rewrites.

for more details about Rewrites to be setup:

https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode

like image 36
vukan Avatar answered Oct 12 '22 03:10

vukan