angular2 rc3 router alpha 3.0.0.7 default route

2019-07-17 01:20发布

angular2 rc3...Using the new router (alpha 3.0.0-alpha.7), how do i specify a default route? useAsDefault is the old router...and '*' doesn't seem to work.

this shoud make it clear what i want...i cannot get the "NotFoundComponent" part working.

export const routes: RouterConfig = [
    { path: 'abc', component: AbcComponent },
    { path: 'def', component: DefComponent },
    { path: '', component: HomeComponent },
    { path: '*', component: NotFoundComponent }  // something like this
];

thanks!

1条回答
Emotional °昔
2楼-- · 2019-07-17 02:01

I believe it should be

{ path: '**', component: NotFoundComponent }

Here is the doc

BTW,

There is a way if you want to set root to default route.

Set pathMatch = 'full' and set redirectTo value

[
  {
    path: '',
    pathMatch: 'full',
    redirectTo: 'teams'
  },
  {
    path: 'teams',
    component: TeamsComponent
  }
]

Here is the blog post talking about this

查看更多
登录 后发表回答