Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

RouterStateSnapshot

Represents the state of the router at a moment in time.

See more...

      
      class RouterStateSnapshot extends Tree<ActivatedRouteSnapshot> {
  url: string
toString(): string }

Description

This is a tree of activated route snapshots. Every node in this tree knows about the "consumed" URL segments, the extracted parameters, and the resolved data.

The following example shows how a component is initialized with information from the snapshot of the root node's state at the time of creation.

      
      @Component({templateUrl:'template.html'})
class MyComponent {
  constructor(router: Router) {
    const state: RouterState = router.routerState;
    const snapshot: RouterStateSnapshot = state.snapshot;
    const root: ActivatedRouteSnapshot = snapshot.root;
    const child = root.firstChild;
    const id: Observable<string> = child.params.map(p => p.id);
    //...
  }
}
    

Properties

Property Description
url: string

The url from which this snapshot was created

Methods

      
      toString(): string
    
Parameters

There are no parameters.

Returns

string