I am using ui-router
, and have a profile
state that looks as follows:
我正在使用ui-router,并且具有如下所示的配置文件状态:
.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
The problem does not occur when I reload my 'landing page' at: http://localhost:9000/
, which has the following state in $stateProvider
:
当我重新加载我的“登录页面”时,问题不会发生:http:// localhost:9000 /,在$ stateProvider中具有以下状态:
.state('home', {
url: "/",
[...]
})
I am using: $locationProvider.html5Mode(true);
我正在使用:$ locationProvider.html5Mode(true);
I tried providing absolute URL as suggested in the Decision Tree here
我尝试在这里提供决策树中建议的绝对URL
I also tried a number of suggestions found online, the most popular being something along these lines (placing it in the app.run()
section):
我也尝试过在线发现的一些建议,最受欢迎的是沿着这些方面的东西(将它放在app.run()部分):
$state.transitionTo($state.current, $stateParams, {
reload: true,
inherit: false,
notify: true
});
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.
在使用和不使用
2 个解决方案
#1
#2
1
When you have html5Mode enabled, the # character will no longer be used in your urls. The # symbol is useful because it requires no server side configuration. Without #, the url looks much nicer, but it also requires server side rewrites.
启用html5Mode后,您的网址中将不再使用#字符。 #符号很有用,因为它不需要服务器端配置。没有#,url看起来更好,但它也需要服务器端重写。
for more details about Rewrites to be setup:
有关要重置的重写的更多详细信息:
#1
2
you need to enable html5mode to true if you want to use your url without '#' prefix.
如果你想使用没有'#'前缀的网址,你需要启用html5mode为true。
Also you need to add your modRewrtie in as mentioned here
你还需要在这里提到你的modRewrtie
Prerequisite:
npm install --save-dev connect-modrewrite
#2
1
When you have html5Mode enabled, the # character will no longer be used in your urls. The # symbol is useful because it requires no server side configuration. Without #, the url looks much nicer, but it also requires server side rewrites.
启用html5Mode后,您的网址中将不再使用#字符。 #符号很有用,因为它不需要服务器端配置。没有#,url看起来更好,但它也需要服务器端重写。
for more details about Rewrites to be setup:
有关要重置的重写的更多详细信息: