gpt4 book ai didi

Angular 路由器 : (TAB like) navigate - how to change URL without running ngOnInit again

转载 作者:太空狗 更新时间:2023-10-29 17:58:44 25 4
gpt4 key购买 nike

OK,问题很简单,但是自己好像找不到答案,求助

我有这条路线(简化):

const routes: Routes = [
{path: '', component: ListPageComponent},
{path: 'd/:id', component: DetailsPageComponent},
{path: ':param1', component: ListPageComponent},
{path: ':param1/:param2', component: ListPageComponent},
{path: ':param1/:param2/:param3', component: ListPageComponent},
{path: '**', component: ListPageComponent}
];

在 ListPageComponent 上,我在顶部有一些选择框过滤器,它们触发 onFilter 方法(简化):

onFilter(filters: any) {
this._router.navigate([
'myroute/',
this.param1,
this.param2,
this.param3
]);
}

现在,我想要的是当我触发此方法并导航(到同一页面组件)时,我不希望该组件再次运行 ngOnInit ...只是为了更改 URL 参数(我是已经订阅了参数更改 - this._route.params.subscribe)

最佳答案

我终于找到了解决方案:Change route params without reloading in angular 2

可以只使用 location.replaceState,在我的案例中就像一个魅力!

关于 Angular 路由器 : (TAB like) navigate - how to change URL without running ngOnInit again,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47875355/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com