dan*_*020 8 router angular angular6
我正在使用 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 }
]
},
];
Run Code Online (Sandbox Code Playgroud)
这是我订阅导航事件的代码:
router.events.subscribe((event: Event) => {
if (event instanceof NavigationStart) {
// Do something here
} else if (event instanceof NavigationEnd) {
// Do something here
}
});
Run Code Online (Sandbox Code Playgroud)
当我使用 router.navigation 时, NavigationEnd 被触发。
但是,如果我转到/dashboard路由器,它将重定向到上述路由文件中的/dashboard/activity,则不会触发该事件。
更新
这是我在StackBlitz 上的示例
只需输入没有任何路径的域,控制台仅在重定向到登录时记录“/”(我更喜欢记录“/登录”)