Working on developing a Single Page Application using AngularJS, my configuration settings appear as follows:
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 aim to allow users to share URLs for individual clients such as: http://myapp.com/#/client/1
, http://myapp.com/#/client/2
, and so forth. The concept is that by entering the URL in the address bar, the user should be directed to the specific client page.
Upon attempting to intercept the $routeChangeStart
event, I noticed that the current
parameter in the event callback is empty upon initial page load, with next.$$route.originalPath
consistently showing up as /
.
$rootScope.$on('$routeChangeStart', function(event, next, current) {
console.log(current); // undefined
console.log(next.$$route.originalPath); // /
console.log(next.$$route.redirectTo); // /clients
});
How can I retrieve the originally requested URL sent to the server to properly navigate to the desired route?
UPDATE
After investigation, it was discovered that the issue stemmed from a redirect set up within the application that redirected all users with a session cookie to /
. This occurred when the user's session token from cookies was extracted.