【发布时间】:2019-08-22 19:05:33
【问题描述】:
我想通过再次路由到同一个路由器来刷新数据。当有第二个(或更多)路由到当前激活的路由时,Angular 不会激活 ngOnInit 组件功能。我想在路由时启用刷新组件上的数据(即使它已经是激活的路由)。我知道这样做的技术很少,但我想使用 RouterEvent 和
NavigationEnd 技术。我知道我需要在
路由模块。
由于某种原因,我无法达到我想要的场景。
查看我的代码:
这是单击按钮时触发的事件(单击按钮两次应该路由两次到同一个组件):
openMapTool(item: MapToolsItem)
{
this.router.navigate([{ outlets: { <Name of router outlet>: ['SomePath', { param1: value1}] }}],);
return false;
}
这是与“SomePath”路径相关的组件(见下文 - “SomeComponent”) - 应该路由两次的组件:
ngOnInit() {
this.subs.push(this.route.events.pipe(
filter(e => e instanceof RouterEvent && e instanceof NavigationEnd),
).subscribe(e =>
{
this.doSomething(e.paramMap);
}));
这是包含“SomePath”路径的模块:
const routes: Routes = [
{ path: 'SomePath', component: SomeComponent, outlet: 'SomeRouterOutlet'}];
@NgModule({
imports: [
RouterModule.forChild(routes),
RouterModule.forRoot(routes, {onSameUrlNavigation:'reload'})]})
感谢您的帮助
【问题讨论】: