[英]Angular2 - Router does not pick up route/home path
我有使用此Angular2 Webpack Starter的 Angular2应用程序。 我刚刚加入到我的后备路线app.routes.ts
文件中添加它的模块(后NotFoundModule
)以app.module.ts
和除了现在我的主路径(一切都很正常''
)不会再注册和NotFoundComponent
负荷。 代码如下:
import { Routes } from '@angular/router';
import { HomeComponent } from './home';
import { NotFoundComponent } from './notfound/notfound.component';
import { DataResolver } from './app.resolver';
export const ROUTES: Routes = [
{
path: '', component: HomeComponent },
{
path: 'getstarted', loadChildren: './getstarted#GetStartedModule'
},
{
path: 'open-account', loadChildren: './open-account/#OpenAccountModule'
},
...
...
...
{
path: '**', component: NotFoundComponent
},
];
如何解决此问题,以便我的本地路由可以再次正常工作,并且NotFoundComponent
不会在其位置加载?
如果您的路线使用''
作为路径且没有子级,则需要为该路线指定pathMatch: 'full'
。
export const ROUTES: Routes = [
{
path: '', pathMatch: 'full', component: HomeComponent },
{
path: 'getstarted', loadChildren: './getstarted#GetStartedModule'
},
{
path: 'open-account', loadChildren: './open-account/#OpenAccountModule'
},
...
...
...
{
path: '**', component: NotFoundComponent
},
];
有关原因,请参见https://angular.io/docs/js/latest/api/router/index/Routes-type-alias.html#!#matching-strategy 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.