角路由器路径参数

问题描述 投票:1回答:1

我有这样的路由器配置。

{
    path: 'home',
    component: HomeComponent,
    children: [
        {
            path: '',
            component: HomeContentComponent
        },
        {
            path: ':id',
            component: HomeContentComponent
        },
        {
            path: 'home2',
            component: HomeComponent
        },
        {
            path: '',
            redirectTo: '',
            pathMatch: 'full',
        },
    ],
}

一切正常。我可以导航到/ home / id1到,我可以像这样读取HomeContentComponent中的参数。

constructor(private activatedRoute: ActivatedRoute) {

this.activatedRoute.params.pipe(
  takeUntil(this.onDestroy)
).subscribe(params => {
  console.log("HERE ARE MY PARAMS ID", params.id);
});
}

现在注销时,我清除本地存储并使用以下导航到登录页面:>

this.router.navigateByUrl('/login');

这很好。但是登录后(也许来自其他用户),我使用[

返回主页。
this.router.navigateByUrl('/home');

我的问题是,它会自动从上一个用户(路由)设置一个旧的ID“ id1”,我可以在控制台输出中看到它,并且浏览器会自动加载/ home / id1而不是/ home。但是我需要导航到/ home路由而没有任何参数。

是否有清除路径参数的方法?

我有这样的路由器配置。 {路径:“ home”,组件:HomeComponent,子代:[{路径:“,组件:HomeContentComponent},{...

angular angular-ui-router
1个回答
0
投票

尝试

© www.soinside.com 2019 - 2024. All rights reserved.