角子路由重定向到父路由而不加载父组件

时间:2020-08-11 18:52:40

标签: angular typescript

更新: 我只是要编辑组件代码,我本来不想做的,但是出于对时间轴的谨慎,我要使用location.go()方法从URL中删除值

我有一个我正在开发的angular 8应用程序。当路由不完整或格式错误时,我正在尝试使子路由重定向到其父路由。使用redirectTo时,应用程序将正确更新url,但似乎没有再次加载该组件。

下面是我的路由器代码示例。

{
    path: 'route1',       
    component: RouteComponent,
    },
    children: [
        {
            path: ':id/:id2',
            component: RouteComponentDetails,                
        },
        {
            path: ':id',
            redirectTo: '/route1',
        },
    ],        
}

如果我设置了这样的路由,该路由将正确地重新加载,但是它将:id参数留在了我不想要的URL中。我还尝试将path设置为**,这将正确更改路由,使用redirectTo时不会重新加载组件。

{
    path: 'route1',       
    component: RouteComponent,
    },
    children: [
        {
            path: ':id/:id2',
            component: RouteComponentDetails,                
        },
        {
            path: ':id',
            component: RouteComponent,
        },
    ],        
}

有没有办法做到这一点?预先感谢?

0 个答案:

没有答案