Help Angular by taking a 1 minute survey!Go to surveyHome

NavigationStart

Represents an event triggered when a navigation starts.

      
      class NavigationStart extends RouterEvent {
  constructor(id: number, url: string, navigationTrigger: "imperative" | "popstate" | "hashchange" = 'imperative', restoredState: { [k: string]: any; navigationId: number; } = null)
  navigationTrigger?: 'imperative' | 'popstate' | 'hashchange'
  restoredState?: {...}
  toString(): string

  // inherited from router/RouterEvent
  constructor(id: number, url: string)
  id: number
  url: string
}
    

Constructor

constructor(id: number, url: string, navigationTrigger: "imperative" | "popstate" | "hashchange" = 'imperative', restoredState: { [k: string]: any; navigationId: number; } = null)
      
      constructor(id: number, url: string, navigationTrigger: "imperative" | "popstate" | "hashchange" = 'imperative', restoredState: { [k: string]: any; navigationId: number; } = null)
    
Parameters
id number
url string
navigationTrigger "imperative" | "popstate" | "hashchange"

Optional. Default is 'imperative'.

restoredState object

Optional. Default is null.

Properties

Property Description
navigationTrigger?: 'imperative' | 'popstate' | 'hashchange'

Identifies the trigger of the navigation.

  • 'imperative'--triggered by router.navigateByUrl or router.navigate.
  • 'popstate'--triggered by a popstate event
  • 'hashchange'--triggered by a hashchange event
restoredState?: { [k: string]: any; navigationId: number; } | null

This reflects the state object that was previously supplied to the pushState call. This is not null only when the navigation is triggered by a popstate event.

The router assigns a navigationId to every router transition/navigation. Even when the user clicks on the back button in the browser, a new navigation id will be created. So from the perspective of the router, the router never "goes back". By using the restoredState and its navigationId, you can implement behavior that differentiates between creating new states and popstate events. In the latter case you can restore some remembered state (e.g., scroll position).

See NavigationExtras for more information.

Methods

toString(): string
      
      toString(): string
    
Parameters

There are no parameters.

Returns

string