I develop SPA using AngularJS. My config looks like this:
app.config(["$routeProvider",
function($routeProvider) {
return $routeProvider
.when("/", {
redirectTo: "/clients"
}).when("/clients", {
templateUrl: "app/views/crm/clients/list.html"
}).when("/client/:id?", {
templateUrl: "app/views/crm/clients/edit.html"
}).when("/404", {
templateUrl: "app/views/pages/404.html"
}).otherwise({
redirectTo: "/404"
});
}
]);
I would like to let my users share URLs for clients: http://myapp.com/#/client/1, http://myapp.com/#/client/2 etc. The idea is that user writes URL to location bar and gets to client page for a specific client.
When I tried to listen for $routeChangeStart event I found out that current parameter in event callback is empty when page is loaded for first time and next.$$route.originalPath is always /.
$rootScope.$on('$routeChangeStart', function(event, next, current) {
console.log(current); // undefined
console.log(next.$$route.originalPath); // /
console.log(next.$$route.redirectTo); // /clients
});
So how can I get the original URL sent to server to use route requested?
UPDATE
As it turned out, the problem was in my own redirect that was triggered when user session token from cookies was extracted. It redirected to / every user who entered application with session cookie.