AngularJS突破路线手动刷新 [英] AngularJS Route breaks on manual refresh
问题描述
在配置方法,我也定义了一些路线如下:
In the config method, I have some routes defined as follows:
$locationProvider.html5Mode(true);
$routeProvider.when('/', {
...
});
$routeProvider.when('/front', {
...
});
$routeProvider.when('/user/account', {
...
});
一切使用&LT通过应用程序导航时工作正常; A HREF =>
标记。然而,当我去 /用户/帐户
键,手动刷新我的浏览器,它会弹出的 /帐户
远离路径并重定向我 /用户
,突破的过程中呈现,因为没有用于定义路线 /用户
。
Everything works fine when navigating through the app using <a href="">
tags. However, when I go to /user/account
and manually refresh my browser, it pops the /account
off the route and redirects me to /user
, breaking the rendering in the process since there is no route defined for /user
.
我注意到,当我配置路由是 /帐户
仅这不会发生,但这并不是固定的真正的问题。所以我设置以下捕获所有(以上航线下方)来记录发生的事情:
I noticed this does not happen when I configure the route to be /account
only, but this is not fixing the real issue. So I set up the following catch-all (below the routes above) to log what's happening:
$routeProvider.otherwise({
redirectTo: function() {
console.log('bumped', arguments);
return '/';
}
});
和看到有人试图匹配 /帐户
而不是 /用户/帐户
。这到底是怎么回事呢?
and saw it was trying to match /account
instead of /user/account
. What is going on here?
我对角1.1.5。服务器返回的index.html适当的方式在所有请求(HTML5模式),所以它似乎是一个客户端的问题。
I am on Angular 1.1.5. The server returns index.html appropriately on all requests (for HTML5 mode), so it seems like a client-side issue.
我怎样才能正确地配置这条路?
How can I configure this route correctly?
修改
原来这是1.1.5内核的错误。
Turns out this is a bug in 1.1.5 core.
https://github.com/angular/angular.js/issues/2799
在这里打补丁
的https://github.com/IgorMinar/angular.js/commit/2bc62ce98f893377bfd76ae211c8af027bb74c1d
推荐答案
结束了使用 UI路由器这解决了这个问题。
Ended up using ui-router which solved this issue.
这篇关于AngularJS突破路线手动刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!