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);
});
}
}
构造函数
参数
|
属性
属性 | 说明 |
---|---|
id: number | 声明在构造函数中 A unique ID that the router assigns to every router navigation. |
url: string | 声明在构造函数中 The URL that is the destination for this navigation. |