Difference between RouterModule component, loadChildren, redirectTo?

1.2K    Asked by RogerLum in Python , Asked on Jan 8, 2020
Answered by Arun Singh

component => A string that acts as a URL for a single route.

redirectTo => Same like component i.e. URL for a single route. Used to redirect URL if available, or use the default URL.

loadChildren => A string that acts as a URL for a set of routes to load, or a function that returns such a set.

Component is to directly link a path to a component, loadChildren is used to load asynchronous components and redirectTo is simply to redirect to another route.

export const ROUTES: Routes = [{

  path: '', redirectTo: 'signin', pathMatch: 'full'

 }, {

   path: 'app', loadChildren: () => System.import('./layout/layout.module')

 }, {

   path: 'login', loadChildren: () => System.import('./login/login.module')

 }, {

   path: 'signin', loadChildren: () => System.import('./signin/signin.module')

 }, {

   path: 'error', component: ErrorComponent

 }, {

   path: '**', component: ErrorComponent

 }

];



Your Answer

Interviews

Parent Categories