gpt4 book ai didi

angular - 延迟加载到 Angular 2 中空路由以外的路由

转载 作者:行者123 更新时间:2023-12-02 11:23:03 25 4
gpt4 key购买 nike

我的app-routing.module.ts如下:

    import { NgModule } from '@angular/core';    import {        Routes,        RouterModule    } from '@angular/router';    const routes: Routes = [        {            path        : 'reset',             loadChildren: 'app/auth/reset-password-form/reset-password-form.module#ResetPasswordFormModule'        },        {            path        : 'verify',            loadChildren: 'app/auth/verify-user-form/verify-user-form.module#VerifyUserFormModule'        },        {            path        : '404',            loadChildren: 'app/route-not-found/route-not-found.module#RouteNotFoundModule'        },        {            path        : '',            pathMatch   : 'full',            loadChildren: 'app/landing-page/landing-page.module#LandingPageModule'        },        {            path      : '**',            redirectTo: '/404'        },    ];    @NgModule({        imports: [RouterModule.forRoot(routes)],        exports: [RouterModule]    })    export class AppRoutingModule {    }

当我导航到localhost:4200时,它将正确加载landing-page.module,但是,当我输入localhost:4200/reset时localhost:4200/verifylocalhost:4200/404,它不会加载相关模块,而是加载landing-page.自动模块

如何解决这个问题?

最佳答案

您必须将路由添加到您的子模块

  const routes: Routes = [
{ path: '', component: ResetComponent}
];
const ROUTES: ModuleWithProviders =
RouterModule.forChild(routes);

并在子模块中导入ROUTES(ResetModule)

@NgModule({
imports: [
CommonModule,
ROUTES,
],
declarations: [ResetComponent],
exports: [ResetComponent]
})

关于angular - 延迟加载到 Angular 2 中空路由以外的路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44065697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com