Unable to redirect to Lazy Loaded module as default route/url on server start up

前端 未结 3 1278
Happy的楠姐
Happy的楠姐 2021-01-25 06:07

Good day folks,

I am having this issue in my Angular 2 application upon server startup (npm start).

I redirect the base route or base path to

3条回答
  •  攒了一身酷
    2021-01-25 06:48

    Try changing your user.module.ts like this :

    @NgModule({
    imports: [
        CommonModule,
        RouterModule.forChild(userRoutes)
    ],
    declarations: [
        LoginComponent
    ],
    exports: [RouterModule], // Add this line
    providers: [UserAuthService]
    })
    
    export class UserModule {}
    

    And routes.ts :

    export const appRoutes:Routes = [
        { path: 'user', loadChildren:  'user/user.module#UserModule'},  
        { path: '', redirectTo: 'user', pathMatch: 'full'}
    ]
    

    Also user.routes.ts :

    export const userRoutes = [
        { path: '', redirectTo: 'login', pathMatch: 'full'},
        { path: 'login', component: LoginComponent }
    ]
    

提交回复
热议问题