ui-router 返回:“Cannot GET/page"

ui-router returns: quot;Cannot GET /pagequot;(ui-router 返回:“Cannot GET/page)
本文介绍了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"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)