What is the difference between ActivatedRouteSnapshot and ActivatedRoute in Angular 4? It's my understanding that ActivatedRouteSnapshot is a child of ActivatedRoute, meaning that ActivatedRoute contains ActivatedRouteSnapshot.
Incidentally, I tried running a Google search for an answer to this question, but I didn't find any of the search results to be understandable.
Thank you!
Since
ActivatedRoutecan be reused,ActivatedRouteSnapshotis an immutable object representing a particular version ofActivatedRoute. It exposes all the same properties asActivatedRouteas plain values, whileActivatedRouteexposes them as observables.Here is the comment in the implementation:
If a router reuses a component and doesn't create a new activated route, you will have two versions of
ActivatedRouteSnapshotfor the sameActivatedRoute. Suppose you have the following routing configuration:Now you navigate to:
You will have the param in the
activatedRoute.snapshot.params.idas1.Now you navigate to:
You will have the param in the
activatedRoute.snapshot.params.idas2.You can see it by implementing the following: