I know there are already several answers to this question but none of them helped me. My issue is that the router redirect doesn't redirect to the correct page and I can't find out why. My setup is:
app-routing.module.ts
export const routes: Routes = [
{ path: '', redirectTo: 'start', pathMatch: 'full' },
{ path: 'start', component: StartComponent, canActivate: [UManagementGuard] },
{ path: 'history', loadChildren: () => import('./history/history.module').then(m => m.HistoryModule), canActivate: [UManagementGuard]
},
{ path: 'preview', component: PreviewComponent, canActivate: [UManagementGuard] },
{ path: 'live', loadChildren: () => import('./live/live.module').then(m => m.LiveModule),
canActivate: [UManagementGuard] },
{ path: 'p-help', component: PHelpComponent },
{ path: '**', redirectTo: '/lotList', pathMatch: 'full'}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {}
So when I run the app it works fine when I start with: http://localhost:4200/start
But when I call http://localhost:4200 or http://localhost:4200/ it displays the PreviewComponent but not the StartComponent???
I already tried:
{ path: '', redirectTo: '/start', pathMatch: 'full' }
or
{ path: '', component: StartComponent }
Any ideas why this might happen?
CodePudding user response:
I finally found the bug.
My PreviewComponent had been a lazy loaded module and I changed it. But I forgot to remove the PreviewRoutingModule which still fired in an redirected any empty Route to it's own start component.