ui-router 返回:“无法获取/页面"; [英] ui-router returns: "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
});
在我的 索引的
.感谢您抽出宝贵时间. 中存在和不存在
<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 如果您想使用不带#"前缀的网址,则为 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 返回:“无法获取/页面";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!