Угловой маршрут по умолчанию redirectTo с loadChildren - PullRequest
0 голосов
/ 22 октября 2018

У меня есть следующее приложение:

const routes: Routes = [
  { path: '', redirectTo: 'demo', pathMatch: 'full' },
  { path: 'demo',  loadChildren: () => ChildModule },
];

imports: [
    RouterModule.forRoot(routes),
],

И он использует этот модуль в loadChildren

const routes: Routes = [
  {
    path: '',  component: DemoComponent,
    children: [
      { path: 'some', component: SomeComponent },
      { path: 'other', component: OtherComponent },
    ],
  },
];

imports: [
    RouterModule.forChild(routes),
],

Если я запускаю приложение, определяются два маршрута:

http://localhost:4200/demo/some

http://localhost:4200/demo/other

Также работает:

http://localhost:4200/some

http://localhost:4200/other

Когда я перехожу на http://localhost:4200/, он не перенаправляется на http://localhost:4200/demo!

Так почему же работают маршруты /some и /other, а перенаправление - нет?

1 Ответ

0 голосов
/ 22 октября 2018
const routes: Routes = [
  { path: '', redirectTo: 'demo', pathMatch: 'full' },
  { path: 'someother',  loadChildren: () => ChildModule },
];

imports: [
    RouterModule.forRoot(routes),
],

=======================================================

const routes: Routes = [
  {
    path: "", redirectTo: "some", pathMatch: "full"
    },
    {
    path: "some",
    component: SomeComponent
    },
    {
    path: "other",
    component: OtherComponent
    }    

];

imports: [
    RouterModule.forChild(routes),
],
...