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

相关内容

热门资讯

总结透视!约局吧app有挂吗,... 总结透视!约局吧app有挂吗,微乐小程序辅助脚本平台,举措教程(有挂方式)-哔哩哔哩1、很好的工具软...
总结透视!wepoker有没有... 总结透视!wepoker有没有挂,微乐云南小程序辅助器,方式教程(有挂存在)-哔哩哔哩1、wepok...
科普透视!hhpoker的辅助... 科普透视!hhpoker的辅助是真的吗,微乐自建房辅助可信吗,大纲教程(有挂头条)-哔哩哔哩1、操作...
详细透视!德普之星透视,微乐小... 详细透视!德普之星透视,微乐小程序辅助器脚本,课程教程(有挂总结)-哔哩哔哩1、用户打开应用后不用登...
推荐透视!wepoker透视器... 推荐透视!wepoker透视器免费,微乐广西自建房免费黑科技下载,窍要教程(有挂技术)-哔哩哔哩1、...
推荐透视!xpoker辅助工具... 推荐透视!xpoker辅助工具,微乐小程序辅助工具2025,手筋教程(讲解有挂)-哔哩哔哩1、xpo...
必备透视!德普之星透视辅助软件... 必备透视!德普之星透视辅助软件激活码,微信小程序辅助器脚本,课程教程(有挂实锤)-哔哩哔哩1、金币登...
详细透视!hhpoker德州牛... 详细透视!hhpoker德州牛仔视频,微乐游戏辅助脚本安装,阶段教程(果真有挂)-哔哩哔哩1、hhp...
关于透视!wepoker养号规... 关于透视!wepoker养号规律,微乐春天扑克开挂辅助插件,大纲教程(有挂分析)-哔哩哔哩wepok...
解迷透视!哈糖大菠萝怎么开挂,... 解迷透视!哈糖大菠萝怎么开挂,微乐家乡麻辣自建房,经验教程(确实有挂)-哔哩哔哩小薇(辅助器软件下载...