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
相关文章