当我在Plunkr中尝试以下代码时PageNotFoundComponent
加载到我的视图中:
src/app-routing.module (摘录)
const appRoutes: Routes = [
{ path: '', redirectTo: '/one', pathMatch: 'full' },
{ path: '**', component: PageNotFoundComponent }
];
当我删除wildcard
路径时,我得到了所需的结果(组件one
加载到视图中):
const appRoutes: Routes = [
{ path: '', redirectTo: '/one', pathMatch: 'full' },
];
我错过了什么?
这是一个笨蛋 https://embed.plnkr.co/MxM5JCJmwHVVSuTdfWZg/
像这样更改@NgModule
:
@NgModule({
imports: [
BrowserModule,
OneModule,//<- before root routing module
AppRoutingModule,
],
declarations: [ AppComponent, PageNotFoundComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule {}
由于OneModule
是在AppRoutingModule
之后,您在OneModule
中的路径将丢失AppRoutingModule's
通配符路径中。