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

相关内容

热门资讯

2026外挂!h5大厅反杀教程... 2026外挂!h5大厅反杀教程,胡乐辅助脚本可靠吗(一贯存在有挂)2026外挂!h5大厅反杀教程,胡...
2026外挂!微信小程序开发,... 2026外挂!微信小程序开发,潮汕来物局开挂方法(本来真的有挂)1、用户打开应用后不用登录就可以直接...
2026外挂!天天海南家园辅助... 2026外挂!天天海南家园辅助,wepoker私人局辅助器(一直是有挂)该软件可以轻松地帮助玩家将w...
2026外挂!老k游戏辅助,涂... 2026外挂!老k游戏辅助,涂山山西辅助(其实是真的有挂);1、任何涂山山西辅助透视是真的假的的玩家...
2026外挂!山西扣点子的技巧... 2026外挂!山西扣点子的技巧,途游四川小程序好运卡(确实有挂)2026外挂!山西扣点子的技巧,途游...
2026外挂!山西扣点子技巧,... 2026外挂!山西扣点子技巧,雀神山庄辅助器(总是存在有挂)1、这是跨平台的山西扣点子技巧轻量版有透...
2026外挂!来来拼十辅助免费... 2026外挂!来来拼十辅助免费辅助,陕西三代二破解(真是有挂)1)来来拼十辅助免费辅助辅助插件:进一...
2026外挂!微信小程序中至赣... 2026外挂!微信小程序中至赣牌圈,微乐小程序授权(竟然真的有挂)1、进入游戏-大厅左侧-新手福利-...
2026外挂!堆堆乐辅助软件,... 2026外挂!堆堆乐辅助软件,四川途游破解安装包(好像是有挂)1、操作简单,无需四川途游破解安装包手...
2026外挂!开心泉州小程序辅... 2026外挂!开心泉州小程序辅助,微乐小程序晃晃脚本(真是真的是有挂)1、起透看视 微乐小程序晃晃脚...