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

相关内容

热门资讯

微乐小程序存在有挂!广西微乐小... 微乐小程序存在有挂!广西微乐小程序脚本(开挂)软件-一直揭幕真的有挂进入游戏-大厅左侧-新手福利-激...
微乐小程序存在有挂!微乐安徽小... 微乐小程序存在有挂!微乐安徽小程序辅助(开挂)挂-果然解谜有挂一、游戏安装教程牌型概率发牌机制”必胜...
微乐小程序透视辅助!微乐贵阳捉... 微乐小程序透视辅助!微乐贵阳捉鸡麻将辅助(开挂)技巧-确实详细是真的挂1、操作简单,无需手机版透视脚...
微乐小程序透视挂!微乐自建房免... 微乐小程序透视挂!微乐自建房免费脚本哪个最好用(开挂)方法-切实普及真的有挂进入游戏-大厅左侧-新手...
微乐小程序透视挂!微乐小程序授... 微乐小程序透视挂!微乐小程序授权(开挂)挂-一贯辅助是有挂1、完成有辅助插件,帮助玩家取得所有比赛的...
微信小程序黑科技免费!微乐辅助... 微信小程序黑科技免费!微乐辅助脚本(开挂)插件-果然科普存在有挂破解侠是真的助透视。每个模型中均包含...
微乐小程序真的有挂!微乐辅助靠... 微乐小程序真的有挂!微乐辅助靠谱麻(开挂)工具-真是透视是真的挂1、玩家可以在透视最简单三个步骤对游...
微乐小程序黑科技!微乐游戏兑换... 微乐小程序黑科技!微乐游戏兑换码大全(开挂)工具-确实详细是真的挂所有人都在同一条线上,像星星一样排...
微信小程序黑科技免费!微乐小程... 微信小程序黑科技免费!微乐小程序辅助(开挂)app-竟然必备存在有挂所有人都在同一条线上,像星星一样...
微信小程序黑科技免费!微信小程... 微信小程序黑科技免费!微信小程序微乐挂如何获取(开挂)神器-确实分享存在有挂1、让任何用户在无需安装...