ui-router返回:“无法GET / page” [英] ui-router returns: "Cannot GET /page"

查看:95
本文介绍了ui-router返回:“无法GET / page”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ui-router ,并且有一个个人资料状态,如下所示:

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

当我在code> http:// localhost:9000 / 上重新加载目标网页时,问题不会发生,其状态如下: $ stateProvider

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: "/",
    [...]
})

我正在使用: $ locationProvider.html5Mode(true);

我尝试提供绝对URL作为sug在决策树中此处

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

我也尝试了一些在线发现的建议,最受欢迎的是这些内容(将它放在 app.run() section):

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
});

使用和不使用< base href =/来测试所有方法> 标记出现在我的 index.html < head> 中。
感谢您的时间。

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.

推荐答案

您需要启用 html5mode 如果您想使用没有#前缀的网址,则为true。

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

您还需要按照提及的方式添加modRewrtie 此处

Also you need to add your modRewrtie in as mentioned here

先决条件:

npm install --save-dev connect-modrewrite

这篇关于ui-router返回:“无法GET / page”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆