如何导航到延迟加载的模块子路由? [英] How can I navigate to lazy loaded module child routes?

查看:65
本文介绍了如何导航到延迟加载的模块子路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用在其路由配置文件中声明的子路由来延迟加载模块, 惰性模块已成功加载,但我无法导航至其子路由.

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 Plunker The 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

推荐答案

正在运行的演示:

Working DEMO : https://plnkr.co/edit/xAGjXqpmkLbCokvCt9qQ?p=info

删除了

pathMatch:'full'

不要无缘无故地在任何地方使用它.

它现在按预期工作.

在此处 https://angular了解更多有关pathMatch的信息.io/docs/ts/latest/guide/router.html#!#redirect

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

这篇关于如何导航到延迟加载的模块子路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆