填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫Home

RouterEvent

路由器相關事件的(而不是關於特定路由的)基底類別。對於任何指定的導航,RouterEvent 只會觸發一次。

Base for events the router goes through, as opposed to events tied to a specific route. Fired one time for any given navigation.

檢視"說明"...

      
      class RouterEvent {
  constructor(id: number, url: string)
  id: number
  url: string
}
    

參見

說明

以下程式碼示範了一個類別是如何訂閱路由器事件的。

The following code shows how a class subscribes to router events.

      
      class MyService {
  constructor(public router: Router, logger: Logger) {
    router.events.pipe(
       filter((e: Event): e is RouterEvent => e instanceof RouterEvent)
    ).subscribe((e: RouterEvent) => {
      logger.log(e.id, e.url);
    });
  }
}
    

建構函式

      
      constructor(id: number, url: string)
    
引數
id number

A unique ID that the router assigns to every router navigation.

url string

The URL that is the destination for this navigation.

屬性

屬性說明
id: number宣告在建構函式中

A unique ID that the router assigns to every router navigation.

url: string宣告在建構函式中

The URL that is the destination for this navigation.