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

  // 继承自 router/RouterEvent
  constructor(id: number, url: string)
  id: number
  url: string
}
    

构造函数

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)
    
参数
id number
url string
navigationTrigger "imperative" | "popstate" | "hashchange"

可选. 默认值是 'imperative'.

restoredState object

可选. 默认值是 null.

属性

属性说明
navigationTrigger?: 'imperative' | 'popstate' | 'hashchange'

表示导航过程中的触发器。

Identifies the trigger of the navigation.

  • 'imperative' —— 由 router.navigateByUrlrouter.navigate 触发。

    'imperative'--triggered by router.navigateByUrl or router.navigate.

  • 'popstate' —— 由 popstate 事件触发。

    'popstate'--triggered by a popstate event

  • 'hashchange' —— 由 hashchange 事件触发。

    'hashchange'--triggered by a hashchange event

restoredState?: { [k: string]: any; navigationId: number; } | null

这里包含的 navigationId 会被用于保存历史记录,以供浏览器导航回来。只有当这次导航是被 popstate 事件触发时,它才不为空。

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.

路由器会把一个 navigationId 赋予每一次路由器过渡/导航。即使用户点击了浏览器的后退按钮,也会创建一个新的 navigationId。 所以,从路由器的视角来看,路由器永远不会 "后退"。借助 restoredState 及其 navigationId,你可以区分开创建新状态和 popstate 事件的行为。 在 popstate 时,你可以恢复一些以前记录的状态(如滚动到的位置)。

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).

欲知详情,参见 NavigationExtras

See NavigationExtrasfor more information.

方法

toString(): string
      
      toString(): string
    
参数

没有参数。

返回值

string