我有一个编辑用户的页面,它有一些子组件在里面。每个子组件都可以更改或对其父组件产生一些影响。
因此,我没有将更改发送到父页面并更新某些字段,而是使用以下命令“重新加载”了当前页面
private route: ActivatedRoute;
reload(){
this.router.navigate(["/admin/user/edit/"+this.user.id]);
}
基本上,它重定向到当前页面。例如,当前页是
http://web.info/admin/user/edit/9
它将被重定向到此页面,希望该页面内的所有数据都重新加载最新的数据。
但是,angular似乎不会使用
如何重新加载当前页面?
编辑:
这就是为什么我需要重新加载页面而不是手动更新当前页面上的数据的原因。我需要在其他组件上做更新,当我做更新时,它将添加一些东西到历史组件。我需要一起刷新User组件和History组件,因为这两个组件都会受到其他组件中更改的影响。
发布于 2021-03-01 17:27:52
看看这个
堆栈闪电战
它使用一个
与
路由器选项。
这一策略确保了angular在导航到它认为“相同”的路由(包括具有不同的路径和查询参数)时,将始终重新呈现组件。
@Injectable()
export class MyStrategy extends RouteReuseStrategy {
shouldDetach(route: ActivatedRouteSnapshot): boolean {
return false;
}
store(route: ActivatedRouteSnapshot, detachedTree: DetachedRouteHandle): void {}
shouldAttach(route: ActivatedRouteSnapshot): boolean {
return false;
}
retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle|null {
return null;
}
shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
return false;
}
}
const routes = [
{path: '2', component: Empty2},
{path: '', component: Empty},
];
@NgModule({
imports: [ BrowserModule, RouterModule.forRoot(routes, {onSameUrlNavigation: 'reload'}) ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ],
providers: [{provide: RouteReuseStrategy, useClass: MyStrategy}]
})
export class AppModule { }
https://stackoverflow.com/questions/52389376
复制相似问题