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

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

问题描述

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

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

当我在 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 这里

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

我还尝试了一些在网上找到的建议,其中最受欢迎的是这些建议(将其放在 app.run() 部分):

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

所有方法都在我的 index 的 <head> 中存在和不存在 <base href="/"> 标记的情况下进行了测试.html.感谢您的宝贵时间.

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<如果您想使用不带#"前缀的网址,则/a> 为 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 返回:“Cannot GET/page"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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