最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ui-router returns: "Cannot GET page" - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question edited Nov 13, 2014 at 8:44 MrTux 34.1k30 gold badges118 silver badges157 bronze badges asked Nov 13, 2014 at 8:41 Nikolay MelnikovNikolay Melnikov 1,3951 gold badge16 silver badges26 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 2

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

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./angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode

发布评论

评论列表(0)

  1. 暂无评论