角度清晰的路由器路径参数

时间:2020-02-14 20:27:08

标签: angular angular-ui-router

我有这样的路由器配置。

{
    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路由而没有任何参数。

有什么方法可以清除路径参数吗?

1 个答案:

答案 0 :(得分:0)

尝试

def test_my_sub_class():
    pkl_instance = # loaded from a pkl file saved from ipython
    test_instance = MySubClass(param1="This was instantiated in 
    test_my_module.py")

    # assert isinstance(pkl_instance, test_instance) fails
    print(pkl_instance.__class__)   # <class 'my_module.MySubClass'>
    print(test_instance.__class__)  # <class 'project.src.my_module.MySubClass'>