【问题标题】:onsameurlnavigation 'reload' not working in angularonsameurlnavigation 'reload' 不能以角度工作
【发布时间】:2020-07-15 01:17:30
【问题描述】:

我遇到的问题是没有重新加载相同的组件。谷歌后发现我需要在 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 { }

下面是我的路由器链接

<a [routerLink]="['/student']">
  Student
</a>

请帮我解决同样的页面加载问题

【问题讨论】:

    标签: angular angular2-routing


    【解决方案1】:

    请注意,onSameUrlNavigation 仅执行守卫和解析器,但不会重新初始化组件。

    您可以使用RouterModule 中的Events 来处理您的场景::

    constructor(private router: Router) {}
    
    ngOnInit() {
      this.router.events.subscribe((event) => {
        if (event instanceof NavigationEnd) {
        // do some logic again when same url is clicked
        }
      });
    }
    

    【讨论】:

      猜你喜欢
      • 2018-08-03
      • 1970-01-01
      • 1970-01-01
      • 2015-01-15
      • 1970-01-01
      • 2017-12-21
      • 1970-01-01
      • 2019-10-15
      • 2020-06-25
      相关资源
      最近更新 更多