Why is ActivatedRoute observed in @angular \ router parameters?

why is ActivatedRoute in @angular\router params is observable ?

I'm wondering why should I subscribe to Params? and why are async parameters the case when a route component will be created, but the parameters are not populated yet?

and is there a way to get the value without observable ?

+6
source share
2 answers

you can use

 route.routerState.params 

You can subscribe because when your application goes to the same route with only a different parameter value, the component does not recreate, and you cannot find out when the parameters have changes.

When you subscribe to the parameters that you receive, a notification that a route has occurred, where only the parameter value has changed.

+10
source

Matrix parameters associated with this route. The observable will emit a new value when changing the set of parameters.

The reason that the params property in ActivatedRoute is observable is because the router cannot recreate the component when navigating to the same component. In this case, the parameter may change without recreating the component.

+1
source

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


All Articles