首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角6在父请求时加载子路由组件

角6在父请求时加载子路由组件
EN

Stack Overflow用户
提问于 2018-09-18 16:54:27
回答 3查看 1K关注 0票数 0

我有我的应用程序的两个部分,一个家庭概况和一个成员配置文件。我的路线设置如下:(简化)

app.routes.ts:

代码语言:javascript
复制
export const appRoutes: Routes = [
    {
      path: 'family/:familyId',
      loadChildren: './core/containers/family/family.module#FamilyModule'
    }
];

family.routes.ts:

代码语言:javascript
复制
export const familyRoutes: Routes = [
    {
        path: 'profile',
        component: FamilyProfileComponent
    },
    {
        path: 'member/:memberId',
        loadChildren: '../member/member.module#MemberModule'
    },
];

member.routes.ts

代码语言:javascript
复制
export const memberRoutes: Routes = [
    {
        path: 'profile',
        component: MemberProfileComponent
    },
];

当我请求

/家庭/fam_1/概况

/家庭/fam_1/成员/mbr_1/概况

这两条路由都显示MemberProfileComponent,而我无法让FamilyProfileComponent显示。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-09-18 18:24:55

原来我的FamilyModule正在导入我的MemberModule,而它本来就不该导入。

票数 0
EN

Stack Overflow用户

发布于 2018-09-18 17:25:14

https://stackblitz.com/edit/angular-hbaucv

这是一个有用的例子,这两个概要文件都可以工作。

家庭简介:1/概况

会员简介:1/概况

app-routing.module.ts

代码语言:javascript
复制
export const appRoutes: Routes = [
  { path: 'family/:familyId', loadChildren: './family/family.module#FamilyModule' }
]

family-routing.module.ts

代码语言:javascript
复制
export const familyRoutes: Routes = [
  { path: 'profile', component: FamilyProfileComponent },
  { path: 'member/:memberId', loadChildren: './member/member.module#MemberModule' }
]

member-routing.module.ts

代码语言:javascript
复制
export const memberRoutes: Routes = [
  { path: 'profile', component: MemberProfileComponent },
]
票数 1
EN

Stack Overflow用户

发布于 2018-09-18 18:02:53

首先,请更改为您的家庭模块文件。

就像这样:

代码语言:javascript
复制
const familyRoutes: Routes = [
  { path: '', redirectTo: 'profile' },
  {
    path: 'profile',
    component: FamilyprofileComponent,
    children: [     
      {
        path: 'member/:memberId',
        loadChildren: './familyprofile/member/member.module#MemberModule'
      }
    ]
  },
];

而不是

代码语言:javascript
复制
const familyRoutes: Routes = [
    {
        path: 'profile',
        component: FamilyProfileComponent
    },
    {
        path: 'member/:memberId',
        loadChildren: '../member/member.module#MemberModule'
    },
];

而不是将<router-outlet>添加到FamilyProfileComponent模板(Html)中。就像这样:

FamilyProfileComponent.html

代码语言:javascript
复制
// Your parent html code
<router-outlet></router-outlet> // Child html content will display here.

这是斯塔克布利茨

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52391346

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档