angular - Router RedirectTo 默认不触发事件 NavigationEnd
问题描述
我正在使用 Angular v6.1.0 和。我的路由文件在这里:
const routes: Routes = [
{
path: '', component: DashboardComponent, children: [
{ path: '', redirectTo: 'activity', pathMatch: 'full' },
{ path: 'activity', component: ActivityComponent },
{ path: 'recent-activity', component: RecentActivityComponent },
{ path: 'notification', component: NotificationComponent }
]
},
];
这是我订阅导航事件的代码:
router.events.subscribe((event: Event) => {
if (event instanceof NavigationStart) {
// Do something here
} else if (event instanceof NavigationEnd) {
// Do something here
}
});
当我使用 router.navigation 时,会触发 NavigationEnd。
但是,如果我转到/dashboard路由器,它将重定向到上述路由文件中的/dashboard/activity,则不会触发该事件。
更新
这是我在StackBlitz
上的示例
只需输入没有任何路径的域,控制台仅在重定向到登录时记录“/”(我更喜欢记录“/登录”)
解决方案
推荐阅读
- ruby-on-rails - 将对象移动到 DEEP_ARCHIVE 的更便宜的方法
- elasticsearch - 将参数从 Airflow 传递到 Logstash
- java - How to use grpc Status Details in package io.grpc
- javascript - 创建新的 js 文件并从其他 js 文件中获取信息
- android - 使用 OpenVPN Connect 连接到 Genymotion Android 中的 VPN
- python - 重新采样 datetime64 时间序列数据帧时出错
- python - 检查是否安装了python 3的问题
- r - 转换时间序列数据的问题
- code-maintainability - 管理长期项目中的解决方法列表
- r - 如何在 r 中跳过不完全空的行