New Angular2 router configuration

后端 未结 3 977
迷失自我
迷失自我 2020-12-01 15:21

Back when using the deprecated router I was able to do a router.config and pass in an object. Thing is, the router itself got configured a bit after the app was started, the

3条回答
  •  青春惊慌失措
    2020-12-01 16:11

    In the new router (>= RC.3) https://angular.io/docs/ts/latest/api/router/index/Router-class.html resetConfig can be used

    router.resetConfig([
     { path: 'team/:id', component: TeamCmp, children: [
       { path: 'simple', component: SimpleCmp },
       { path: 'user/:name', component: UserCmp }
     ] }
    ]);
    

    You might need to provide some dummy router configuration to not get errors on application startup.

    https://github.com/angular/angular/issues/11437#issuecomment-245995186 provides an RC.6 Plunker

提交回复
热议问题