How can I navigate to lazy loaded module child routes?

早过忘川 提交于 2019-12-05 18:01:56

Working DEMO : https://plnkr.co/edit/xAGjXqpmkLbCokvCt9qQ?p=info

Removed unnecessary usage of

pathMatch:'full'

Don't use it everywhere without any reason.

And its now working as expected.

learn more about pathMatch here https://angular.io/docs/ts/latest/guide/router.html#!#redirect, https://angular.io/docs/ts/latest/api/router/index/Routes-type-alias.html

I had the same issue, in my case no error appear but the view doesnt load, I can solved the problem by this way:

  • This is my lazy module
const routes: Routes = [
  {
    path: ''
    },
    children: [
      { path: '', component: AdminComponent },
      { path: 'users', component: AdminUsersComponent },
      { path: 'games', component: AdminGamesComponent },
      { path: '**', redirectTo: '' }
    ]
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class AdminRoutingModule { }
  • This is my root module
const routes: Routes = [
  {
    path: 'admin', loadChildren: 'app/admin/admin.module#AdminModule'
  }
];

@NgModule({
  imports: [RouterModule.forRoot(routes, { enableTracing: !environment.production })],
  exports: [RouterModule]
})
export class AppRoutingModule { }

Now the routes:

  • admin/
  • admin/users
  • admin/games

works perfectly

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