问题描述
我正在尝试使用在其路由配置文件中声明的子路由来延迟加载模块,惰性模块已成功加载,但我无法导航至其子路由.
I am trying to lazy load module with child routes declared in it's routing configuration file,The lazy module loaded successfully but I can't navigate to it's child routes.
我正在使用该技术,就像它是一个急切加载的模块一样.我声明了路径,里面是孩子.请参阅Plunker中的"moduleB"路由文件链接按钮正在尝试导航到子路线并加载CmpC.但是失败了.
I am using the technique as if it were a eagerly loaded module.I declared path and inside it it's children.Please see 'moduleB' routing file in the PlunkerThe link button is trying to navigate to the child route and load CmpC. but it fails.
这是我的根模块路由缩放比例:
Here is my root module routing decalration:
{ path: 'feature-b', loadChildren:'src/featureB/featureB.module#FeatureBModule' , pathMatch: 'full'}
这是我的延迟加载的模块路由声明.
Here is my lazy loaded module routing declaration.
export const moduleBRoutes: Routes = [
{ path: '', component:CmpC , pathMatch: 'full',children:[
{path: '' , pathMatch: 'full'},
{ path: 'c', component:CmpB , pathMatch: 'full'}
]},
];
export const subRouting: ModuleWithProviders = RouterModule.forChild(moduleBRoutes);
尝试导航到:localhost:999/feature-b成功
trying to navigate to : localhost:999/feature-b succeeded
尝试导航到:localhost:999/feature-b/c失败
trying to navigate to : localhost:999/feature-b/c failed
https://plnkr.co/edit/wFlJoDXRmAlMOswmwWFk?p=preview
推荐答案
正在运行的演示: https://plnkr.co/edit/xAGjXqpmkLbCokvCt9qQ?p=info
Working DEMO : https://plnkr.co/edit/xAGjXqpmkLbCokvCt9qQ?p=info
删除了
pathMatch:'full'
不要无缘无故地在任何地方使用它.
它现在按预期工作.
在此处 https://angular了解更多有关pathMatch
的信息.io/docs/ts/latest/guide/router.html#!#redirect , https://angular.io/docs/ts/latest/api/router/index/Routes-type-alias.html
learn more about pathMatch
here https://angular.io/docs/ts/latest/guide/router.html#!#redirect, https://angular.io/docs/ts/latest/api/router/index/Routes-type-alias.html
这篇关于如何导航到延迟加载的模块子路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!