问题
In the config method, I have some routes defined as follows:
$locationProvider.html5Mode(true);
$routeProvider.when('/', {
...
});
$routeProvider.when('/front', {
...
});
$routeProvider.when('/user/account', {
...
});
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?
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?
EDIT
Turns out this is a bug in 1.1.5 core.
https://github.com/angular/angular.js/issues/2799
patched here
https://github.com/IgorMinar/angular.js/commit/2bc62ce98f893377bfd76ae211c8af027bb74c1d
回答1:
Ended up using ui-router which solved this issue.
来源:https://stackoverflow.com/questions/18171230/angularjs-route-breaks-on-manual-refresh