Angular2 $ routeChangeStart, $ routeChangeSuccess, $ routeChangeError

In angular2, what is equivalent to these corner events?

$ routeChangeStart, $ routeChangeSuccess, $ routeChangeError

I want to use these events in the root component of the application to change any route.

early

Update

  • If I use OnActivate, OnDeactivate events, it should add it to each component :(

  • I also tried to implement my own RouterOutlet, but I can’t access the previous instructions for activating, deactivating events, I also don’t know how to handle the route. Change Error

  • Also, router.subscribe gave me only a name, but I want the current and next command objects to change some properties

My goal:

1- Show the loading indicator at the start of the shift page and hide it when loading the page.

2- Make a transitional rtl or ltr animation for the current and next command

+4
source share
2 answers

There are events such as OnActivate, OnDeactivateand protective functions, CanActivateand CanDeactivatewhich you can look at.

See the documentation for Router

+2
source

I solved the problem, for anyone who encounters this problem, you can create your own RouterOutlet directive, which inherits RouterOutlet, and then use it as a proxy

+1
source

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


All Articles