如何访问路由启动和路由结束事件? 我想在路由和加载数据时显示进度条。
有人能告诉我这是如何运作的吗?
答案 0 :(得分:2)
如果您更喜欢使用observable:
import { Router, NavigationStart } from '@angular/router';
...
constructor(router:Router) {
router.events.subscribe(e => {
if(e instanceof NavigationStart) {
// Init Code
}
if(e instanceof NavigationEnd) {
// Exit Code
}
}
});