Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何重新加载具有相同url的页面_Angular_Angular Routing_Angular9 - Fatal编程技术网

Angular 如何重新加载具有相同url的页面

Angular 如何重新加载具有相同url的页面,angular,angular-routing,angular9,Angular,Angular Routing,Angular9,我需要重新加载页面在同一个网址的角度。所以我读了这个解决方案,它是有效的: this.router.navigateByUrl('/RefreshComponent', { skipLocationChange: true }).then(() => { this.router.navigate(['Your actualComponent']); }); 我的问题是:这是一个糟糕的解决方案吗? 首先需要加载一个url,然后重定向到另一个url?如果这是一个糟糕的解决方案,有人可

我需要重新加载页面在同一个网址的角度。所以我读了这个解决方案,它是有效的:

this.router.navigateByUrl('/RefreshComponent', { skipLocationChange: true }).then(() => {
    this.router.navigate(['Your actualComponent']);
});
我的问题是:这是一个糟糕的解决方案吗?
首先需要加载一个url,然后重定向到另一个url?如果这是一个糟糕的解决方案,有人可以告诉我吗?

您可以像这样重新加载当前页面:

 location.reload();

在导入路线的
批准模块中按如下方式导入:

@NgModule({
  imports: [RouterModule.forRoot(routes, {
    onSameUrlNavigation: 'reload'
  })],
  exports: [RouterModule]
})
export class AppRoutingModule {
}

您不必首先导航到另一个url

以下代码适用于您:

this.router.routeReuseStrategy.shouldReuseRoute=函数(){
返回false;
};

yash问题是,我有一个包含两个菜单项a和B的菜单。我刚刚尝试了你的解决方案,当我第一次重新加载页面时,它可以工作,但当我转到另一个B,回到a后,带有url B的组件网没有加载,而是加载组件a