首页 > 解决方案 > 页面重新加载后Angular 9不需要的重定向

问题描述

我很难理解 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(包含路由器插座)的一部分。

但是当我现在从浏览器调用时(例如刷新/F5):

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

那么我怎样才能防止这种重定向呢?

标签: angularangular-routingangular-router

解决方案


尝试这个,

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

推荐阅读