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']); //导航到非子组件 } }

相关内容

热门资讯

总算明白!悦扑克脚本,wepo... 总算明白!悦扑克脚本,wepoker怎么设置盖牌,切实存在有挂(有挂方法)1、辅助软件下载优化,底牌...
来一盘!wepoker私人局俱... 来一盘!wepoker私人局俱乐部,wepoker正确养号方法,都是真的有挂(的确有挂)1、上手简单...
实测交流!wepoker怎么设... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...
关于!wepoker怎么增加运... 关于!wepoker怎么增加运气,wepoker软件安装包,都是存在有挂(揭秘有挂)1、实时透视辅助...
今日公布!wpk官网下载链接,... 今日公布!wpk官网下载链接,sohoo poker辅助,原来真的有挂(有挂工具)在进入软件靠谱后,...
一分钟揭秘!wepoker透视... 一分钟揭秘!wepoker透视脚本苹果版,hhpoker是正品吗,竟然真的有挂(有挂秘笈)1、完成辅...
查到实测!wpk软件是真的吗,... 查到实测!wpk软件是真的吗,有哪些免费的wpk作弊码,其实存在有挂(证实有挂)1、游戏颠覆性的策略...
玩家攻略推荐!哈糖大菠萝开挂,... 玩家攻略推荐!哈糖大菠萝开挂,we poker游戏下,确实真的有挂(有挂方法)1、免费脚本咨询教程、...
安装程序教程!wepoker模... 安装程序教程!wepoker模拟器哪个好用,hhpoker是内部控制吗,竟然是真的有挂(确实有挂)1...
科普攻略!破解辅助插件wepo... 科普攻略!破解辅助插件wepoker,wepoker透视脚本是什么,好像是真的有挂(真的有挂)1、脚...