Angular 角形路由器防护装置在按下后退按钮时未调用
我有一个运行在iframe中的Angular应用程序,它为我正在运行的模块提供了一个路由保护。每当我使用应用程序内部的链接或通过地址栏导航到页面,并将应用程序路由到正确的组件时,route guard就会被激活。但由于某种原因,当我从组件中单击“后退”按钮时,模块的route guard无法启动,应用程序被导航到模块的基本组件-这不应该发生 我已经测试并确认,当我按下其中一个组件内的“后退”按钮时,路由器事件确实会被触发:Angular 角形路由器防护装置在按下后退按钮时未调用,angular,angular-routing,angular-router,angular-router-guards,Angular,Angular Routing,Angular Router,Angular Router Guards,我有一个运行在iframe中的Angular应用程序,它为我正在运行的模块提供了一个路由保护。每当我使用应用程序内部的链接或通过地址栏导航到页面,并将应用程序路由到正确的组件时,route guard就会被激活。但由于某种原因,当我从组件中单击“后退”按钮时,模块的route guard无法启动,应用程序被导航到模块的基本组件-这不应该发生 我已经测试并确认,当我按下其中一个组件内的“后退”按钮时,路由器事件确实会被触发: export class FourthComponent { co
export class FourthComponent {
constructor(private readonly router: Router) {
this.router.events.subscribe((event: NavigationStart) => {
if (event.navigationTrigger === 'popstate') {
console.log('back or forward button clicked');
}
});
}
每当我从辅助组件屏幕单击后退按钮时,控制台日志都会打印
下面是子模块的路由模块routes
数组:
const routes: Routes = [
{
path: '',
canActivate: [SubModuleGuard],
children: [
{
path: 'first',
component: FirstComponent
},
{
path: 'second',
component: SecondComponent
},
{
path: 'third',
component: ThirdComponent
},
{
path: 'fourth',
component: FourthComponent
},
{
path: '**',
component: BaseComponent
}
]
}
];
出于某种原因,每次我从FourthComponent
单击back按钮时,都会导航到BaseComponent(可能是子模块的所有子组件的情况)。如果我再次单击后退按钮,它也会对iframe的父对象执行后退操作
请告诉我为什么route guard(在本例中为SubModuleGuard)不会启动,以及当单击“后退”按钮时,我如何强制route guard启动。如果在路由配置中添加
Runguard和Resolver:“always”
,则会发生什么情况,如下canActivate:[SubModuleGuard],
?如果在路由配置中添加梯级守卫和解析器:“始终”
,在激活:[SubModuleGuard],
下面,会发生什么情况?