Angular 7 - 如何检查用户是否直接导航到页面
Angular 7 - how to check if the user directly navigate into the page
我有一个具有下一个路由结构的应用程序:
{
path: "home",
component: HomeComponent,
children: [
{
path: "list",
component: ListViewComponent
},
{
path: "dashboard",
component: DashboardComponent
},
{
path: '',
pathMatch: 'full',
redirectTo: 'dashboard'
},
{
path: "**",
redirectTo: 'dashboard'
}
]
}
如何检查用户是通过完整路径(例如 home/list
还是 redirectTo
导航到页面?
您可以通过添加以下内容来查看 url:
path: 'team/:id',
component: TeamComponent,
canActivate: ['canActivateTeam']
这里['canActivateTeam']可以是服务中的函数。
您可以在导航至 url 时使用状态并向其传递用户定义的值。
根据 angular 文档:
Developer-defined state that can be passed to any navigation. Access this value through the Navigation.extras object returned from router.getCurrentNavigation() while a navigation is executing.
我有一个具有下一个路由结构的应用程序:
{
path: "home",
component: HomeComponent,
children: [
{
path: "list",
component: ListViewComponent
},
{
path: "dashboard",
component: DashboardComponent
},
{
path: '',
pathMatch: 'full',
redirectTo: 'dashboard'
},
{
path: "**",
redirectTo: 'dashboard'
}
]
}
如何检查用户是通过完整路径(例如 home/list
还是 redirectTo
导航到页面?
您可以通过添加以下内容来查看 url:
path: 'team/:id',
component: TeamComponent,
canActivate: ['canActivateTeam']
这里['canActivateTeam']可以是服务中的函数。
您可以在导航至 url 时使用状态并向其传递用户定义的值。
根据 angular 文档:
Developer-defined state that can be passed to any navigation. Access this value through the Navigation.extras object returned from router.getCurrentNavigation() while a navigation is executing.