填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写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
}
    

参见

构造函数

constructor(id: number, url: string)
      
      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: numberDeclared in constructor.

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

url: stringDeclared in constructor.

The URL that is the destination for this navigation.

使用说明

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); }); } }
      
      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);
    });
  }
}