angular2 rc3 router alpha 3.0.0.7 default route

不想你离开。 提交于 2019-12-24 00:58:40

问题


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:


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



来源:https://stackoverflow.com/questions/38110453/angular2-rc3-router-alpha-3-0-0-7-default-route

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!