[英]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: 版本:
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.html
的base 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.