我有以下路由设置:
应用程序的路由
const routes: Routes = [
{ path: '', component: YardListComponent},
{ path: 'yards/new', component: YardEditComponent},
{ path: 'yards/:id', component: YardDetailComponent},
{ path: 'yards/:id/edit', component: YardEditComponent},
];
码的路由
"Packages": [
{
"IsESignAllowed": false,
"IsEnabled": true,
"Name": "Brokerage Accounts Package",
"PackageId": 2
}
]
目前,如果我浏览到顶层不存在的网址,我会找到未找到的网页。但是,当我想要访问任何子页面时,如果我也找到了未找到的页面,例如:yards / 1或yards / new
如何设置我的路由以确保我可以查看子页面但是还找不到适用于所有级别的页面?
答案 0 :(得分:0)
您需要在通配符之前放置您的子路线。例如,我有一个主要部分的路线,你有“顶级”,然后是第二组路线,你可以放置你的码页。
export const AppRoutes: Routes = [{
path: '',
redirectTo: 'home',
pathMatch: 'full',
},
{
path: '',
component: AdminLayoutComponent,
children: [{
path: 'home',
loadChildren: './dashboard/dashboard.module#DashboardModule'
},{
// path: 'runs',
// loadChildren: './tables/tables.module#TablesModule'
// },{
path: 'calendar',
loadChildren: './calendar/calendar.module#CalendarModule'
},{
path: '',
loadChildren: './userpage/user.module#UserModule'
},
{
path: 'analytics',
// component: StatsComponent
component: Analytics
}]
},
{
path: 'forbidden',
// component: StatsComponent
component: ForbiddenComponent
},
{
path: '',
component: AuthLayoutComponent,
children: [{
path: 'pages',
loadChildren: './pages/pages.module#PagesModule'
}]
},{
path: '**',
redirectTo: '/home',
pathMatch: 'full'
}
];