Angular无法导航到嵌套的非子组件
创始人
2024-10-30 01:00:15
0

要导航到非子组件,我们需要使用路由对象和路由路径来手动导航。以下是一个具体的示例:

  1. 在根路径下的路由配置文件中,为非子组件添加路由路径。
const appRoutes: Routes = [
  { path: 'home', component: HomeComponent},
  { path: 'about', component: AboutComponent},
  { path: 'parent', component: ParentComponent,
    children: [
      { path: 'childOne', component: ChildOneComponent },
      { path: 'childTwo', component: ChildTwoComponent },
    ]
  },
  { path: 'non-child', component: NonChildComponent } //添加非子组件的路由路径
];
  1. 在导航组件中导入路由服务和路由对象,使用router.navigate()方法来手动导航到非子组件。
import { Component } from '@angular/core';
import { Router } from '@angular/router';

@Component({
  selector: 'app-parent',
  template: `
    

Parent Component

`, }) export class ParentComponent { constructor(private router: Router) {} navigateToChildOne() { this.router.navigate(['/parent/childOne']); //导航到子组件 } navigateToChildTwo() { this.router.navigate(['/parent/childTwo']); //导航到子组件 } navigateToNonChild() { this.router.navigate(['/non-child']); //导航到非子组件 } }

相关内容

热门资讯

7分钟辅助!pokemmo手机... 7分钟辅助!pokemmo手机版脚本免费,wepoker数据分析工具,手册教程(有挂透视)暗藏猫腻,...
6分钟辅助!aapoker能控... 6分钟辅助!aapoker能控制牌吗,pokemmo脚本最新版,教程书教程(有挂辅助)1、aapok...
第3分钟辅助!werplan脚... 第3分钟辅助!werplan脚本,德普之星透视辅助插件,技法教程(有挂方法)1、德普之星透视辅助插件...
四分钟辅助!wpk是真的还是假... 四分钟辅助!wpk是真的还是假的,we poker辅助器下载,练习教程(有挂解密)1、下载好wpk是...
第2分钟辅助!哈糖大菠萝有挂吗... 第2分钟辅助!哈糖大菠萝有挂吗,hh poker辅助有用吗,指南教程(详细教程)哈糖大菠萝有挂吗脚本...
六分钟辅助!wepoker作弊... 六分钟辅助!wepoker作弊辅助,德州之星扫描器,诀窍教程(有挂秘籍)1、每一步都需要思考,不同水...
第七分钟辅助!wepoker透... 第七分钟辅助!wepoker透视脚本下载,德普之星私人局辅助免费,模块教程(有挂实锤)1、让任何用户...
第6分钟辅助!德州hhpoke... 第6分钟辅助!德州hhpoker脚本,pokemmo手机版脚本免费,妙招教程(有挂神器);1、完成p...
第6分钟辅助!uupoker透... 第6分钟辅助!uupoker透视,wepoker有辅助吗,攻略教程(有挂工具)1、起透看视 wepo...
7分钟辅助!德普之星透视辅助软... 7分钟辅助!德普之星透视辅助软件激活码,werplan外卦神器,法门教程(有挂辅助)1、德普之星透视...