[英]Nested Child route in Angular 13
I want to navigate nested child routes using children inside app-routing.ts file.我想使用 app-routing.ts 文件中的子级导航嵌套的子级路由。 But my components not get called.
但是我的组件没有被调用。
code is as follows: app-routing.ts file代码如下:app-routing.ts文件
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { SubmitFeedbackComponent } from './submit-feedback/submit-feedback.component';
import { MenuOptionsComponent } from './menu-options/menu-options.component';
import { InteviewDetailsComponent } from './menu-options/inteview-details/inteview-
details.component';
import { EditFeedbackComponent } from './menu-options/edit-feedback/edit-feedback.component';
import { SkillListComponent } from './menu-options/skills/skill-list/skill-list.component';
import { SkillAddComponent } from './menu-options/skills/skill-add/skill-add.component';
import { SkillEditComponent } from './menu-options/skills/skill-edit/skill-edit.component';
const routes: Routes = [
{
path: 'menu-list',
component: MenuOptionsComponent,
children: [
{
path: 'inteview-details',
component: InteviewDetailsComponent,
pathMatch: 'full'
},
{
path: 'edit-feedback',
component: EditFeedbackComponent,
},
{
path: 'skill-list',
component: SkillListComponent,
children:[
{ path: 'skill-add', component: SkillAddComponent },
{ path: 'skill-edit', component: SkillEditComponent },
]
}
]
},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
Below is the folder structure下面是文件夹结构
I'm hitting URL is like : http://localhost:4200/menu-list/skill-list/skill-add我打的网址是这样的:http://localhost:4200/menu-list/skill-list/skill-add
As per above URL only up to skill list component is loading.根据上面的 URL,仅加载技能列表组件。 skill-add is getting inside URL but on browser skill-add component is not loading.
技能添加正在进入 URL,但浏览器技能添加组件未加载。 Also no any errors is there.
也没有任何错误。 Please let me know what I can do there.
请让我知道我可以在那里做什么。
I feel you're confused about router children.我觉得你对路由器孩子感到困惑。 A router children is when you want to have a component and, inside it, another component.
路由器子代是当您想要拥有一个组件并在其中拥有另一个组件时。 For this your parent component should to have a
<router-outlet></router-outlet>
, eg为此,您的父组件应该有一个
<router-outlet></router-outlet>
,例如
Your main.component is你的 main.component 是
<router-outlet></router-outlet>
And your SkillListComponet like和你的 SkillListComponet 一样
<p>I'm the SkillListComponent</p>
<router-outlet></router-outlet>
But you can to have a path like (see that it's not belong to any "children"但是你可以有一个像这样的路径(看看它不属于任何“孩子”
{path: 'skill-list/skill-add,component: SkillAddComponent }
And the "SkillAddComponent" is render in the main.component并且“SkillAddComponent”在 main.component 中呈现
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.