Raj*_*mar 7 angular2-routing angular
我面临的问题是不重新加载相同的组件。谷歌之后我发现我需要在 app-routing-module.ts 文件中添加onsameurlnavigation“reload”,但这也不起作用
下面是我的 app-routing-module.ts 代码
const routes: Routes = [
{ path: 'student', component: StudentDetailsComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes,{onSameUrlNavigation: 'reload'})],
exports: [RouterModule]
})
export class AppRoutingModule { }
Run Code Online (Sandbox Code Playgroud)
下面是我的路由器链接
<a [routerLink]="['/student']">
Student
</a>
Run Code Online (Sandbox Code Playgroud)
请帮助我解决同一页面加载问题
Akh*_*hil 13
请注意,onSameUrlNavigation仅执行守卫和解析器,但不会重新初始化组件。
您可以使用类似的Events方法RouterModule来处理您的场景::
constructor(private router: Router) {}
ngOnInit() {
this.router.events.subscribe((event) => {
if (event instanceof NavigationEnd) {
// do some logic again when same url is clicked
}
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9168 次 |
| 最近记录: |