我今天需要路由方面的帮助。我有一组组件,每个组件都有不同的路线。我想在父级和子级中为通配符路由添加“PageNotFoundComponent”。我的意思是,这是我的网址:
http://localhost:8888/programs/cohorts
cohorts
是 的孩子programs
。我想重定向到PageNotFoundComponent
任何一个programs
或cohorts
错误的时候。这是我的代码:
应用程序路由.module.ts
...
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
const routes: Routes = [
{ path: 'login', component: LoginComponent },
{
path: '',
component: ProgramsComponent,
canActivate: [AuthGuard]
children: [
{
path: 'programs/:dashboardId',
component: DashboardComponent
},
{
path: 'programs/:dashboardId/:subPageId',
component: DashboardComponent
},
{
path: 'programs/**',
component: PageNotFoundComponent
}
]
},
{ path: '**', component: PageNotFoundComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
providers: [DashboardModelResolver, DashboardListResolver]
})
export class AppRoutingModule {}
我在某个地方犯了错误。请指出并帮助我。
这工作得很好:http://localhost:8888/prrrooogrm/cohorts
但这是给空白屏幕:http://localhost:8888/programs/cooohrt
我也试过这个:
imports: [
RouterModule.forRoot(routes),
RouterModule.forChild([
{
path: '**',
component: PageNotFoundComponent
}
])
],