重新加载页面后,Angular 9不需要的重定向

时间:2020-09-15 10:44:35

标签: angular angular-routing angular-router

我在了解Angular路由器行为时遇到问题。当前,路由模块如下所示:

const routes: Routes = [
{
    path: '',
    component: ManageCompetitionComponent,
    children: [
        {
            path: ':eventID',
            component: EventProfileComponent,
        },
    ],
}];

当我打开http://localhost:4200/admin/competition并单击导航到http://localhost:4200/admin/competition/1234的链接时,它工作正常,并且EventProfileComponent显示为ManageCompetitionComponent的一部分(包含路由器出口)

但是当我现在从浏览器拨打电话时(例如,refresh / F5):

http://localhost:4200/admin/competition         -> works fine
http://localhost:4200/admin/competition/1234    -> redirects to /admin/competition

那么我该如何防止重定向?

1 个答案:

答案 0 :(得分:0)

尝试一下

const routes: Routes = [
{
    path: '',
    component: ManageCompetitionComponent,
   
}, 
{
    path: ':eventID',
    component: EventProfileComponent,
}];