角度 2 路由器与路径不匹配



当我在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通配符路径中。

最新更新