Search code examples
angularangular6angular-routing

Default path in a path with children


I am using angular 6 and for the cms of the app I have the following paths set up in the app.modules.ts file.

{ path: 'cms', component: CmsComponentComponent, children: [
  { path: 'register', component: RegisterComponent },
  { path: 'login', component: LoginComponent },
  { path: 'profile', component: ProfileComponent, canActivate:[AuthGuard] },
  { path: 'educate', component: EducateComponent, canActivate:[AuthGuard] }
]},

I would like to have a default cms, so if I type app/cms I would got to Register.

How can I do this?

Thanks


Solution

  • From my understanding, you only have to add a redirect route like this:

    { path: 'cms', component: CmsComponentComponent, children: [
      { path: 'register', component: RegisterComponent },
        ...
      { path: '', redirectTo: '/register', pathMatch: 'full' }
    ]},