AngularJs - Determining the next location route in $ locationChangeStart

I recently found out about the undocumented $ locationChangeStart event in AngularJS when I tried to determine where, within the framework, I should redirect users to the login page if their session is invalid.

I am listening to the event using the following:

$scope.$on("$locationChangeStart", function (event, nextLocation, currentLocation) { // Logic goes here }); 

where nextLocation and previousLocation are the absolute URLs for locations in the application.

My question is this: Does AngularJS allow you to map a URL to a route, like its internal routing mechanism, to determine if an absolute URL matches a specific route?

If not, what would be the best way to determine a route based on an absolute URL?

+4
source share
1 answer

I placed the corresponding lines of source code in the angularJS github project. Here is a function that is used to map a URL to a route:

Since this functionality is not disclosed by Angular, I decided to come up with a primitive way to map the URL to the route, since the routes I mapped were relatively simple compared to implementing the same route matching as Angular.

It is not very, but it works.

+3
source

Source: https://habr.com/ru/post/1490309/


All Articles