简体   繁体   English

Angular 7子路由延迟加载模块不起作用

[英]Angular 7 sub-routing lazy-loaded modules are not working

Accessing child module of parent module localhost:4200/child/subchild gives out the error in the console localhost:4200/child/runtime.js is not found - 404 访问父模块localhost:4200/child/subchild子模块会在控制台localhost:4200/child/runtime.js中找到错误localhost:4200/child/subchild

Going to localhost:4200/child would load the child component but in going to /child/subchild would load a blank page, and the 404 error message on the console. 进入localhost:4200/child将加载子组件,但进入/child/subchild则将加载空白页,并在控制台上显示404错误消息。

Versions: 版本:

  • Angular (core, router) - 7.2.3 角度(核心,路由器)-7.2.3
  • Angular CLI - 7.3.0 Angular CLI-7.3.0
  • Node - 10.12 节点-10.12

Main Module 主模块

const routes: Routes = [{
    path: "child",
    loadChildren: "./modules/child/child.module#ChildModule",
}, {
    path: "",
    pathMatch: "full",
    redirectTo: "",
}];
@NgModule({
    declarations: [AppComponent],
    imports: [
        RouterModule.forRoot(routes),
        ...
    ]
})

Child Module 子模块

const routes: Routes = [{
    path: "",
    component: ChildComponent,
    children: [
        { path: "subchild", component: SubchildComponent }
    ]
}];
@NgModule({
    declarations: [ChildComponent, SubchildComponent],
    imports: [
        RouterModule.forChild(routes),
        ...
    ]
})

The page page should display without any errors on going to the url: http://localhost:4200/child/subchild 该页面页面应显示为正确无误,但转到URL: http://localhost:4200/child/subchild

I have found the cause of this issue since I changed the base href of index.html . 自从更改index.htmlbase href以来,我已经找到了导致此问题的原因。

Reverted it from base href='./' to base href='/' . 将其从base href='./'恢复为base href='/'

I changed the base href this way since I was also compiling this angular project to Android using Cordova. 我以这种方式更改了基本href,因为我也使用Cordova将这个角度项目编译为Android。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular:使用路由对延迟加载的模块进行单元测试 - Angular: Unit testing lazy-loaded modules with routing 角度5:如何路由嵌套的延迟加载模块? - Angular 5: How to routing nested lazy-loaded modules? 安全地保护延迟加载的模块(Angular 2) - Securely Guarding Lazy-Loaded Modules (Angular 2) 具有多个命名出口的延迟加载模块上的Angular2路由 - Angular2 Routing on lazy-loaded module with multiple named outlets 角度的 <custom-component> 在延迟加载的模块上不起作用 - Angular <custom-component> doesnt work on lazy-loaded modules 将 Angular 从 8 更新到 9 后延迟加载的模块警告 - Lazy-loaded modules warnings after updating Angular from 8 to 9 离子事件在延迟加载的模块之间无法正常工作 - Ionic events not working correctly between lazy-loaded modules 延迟加载的 Angular 模块无法使用@nguniversal 渲染服务器端,而客户端路由和渲染工作 - Lazy-loaded Angular modules don't get server side rendered with @nguniversal, while client side routing and rendering works 来自延迟加载模块的Angular 2延迟加载模块 - Angular 2 lazy-loading modules from within a lazy-loaded module Angular2定义子路由模块的子路由 - Angular2 Define child routes from sub-routing module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM