Sunday, 11 August 2013

AngularJS Route breaks on manual refresh

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', {
...
});
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?

No comments:

Post a Comment