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

相关内容

热门资讯

透视好牌!德普之星辅助工具如何... 透视好牌!德普之星辅助工具如何设置,德普之星辅助工具如何打开(透视)其实是真的挂(确实有挂)-哔哩哔...
现就发布提示!微友亲友圈辅助器... 现就发布提示!微友亲友圈辅助器,财神13章透视,绝活儿教程(有挂辅助)-哔哩哔哩1、微友亲友圈辅助器...
辅助透视!德普之星透视辅助软件... 辅助透视!德普之星透视辅助软件是真的吗,如何下载德普之星辅助软件(透视)真是是有挂(有挂秘诀)-哔哩...
有了最新消息!如何下载河洛杠次... 有了最新消息!如何下载河洛杠次脚本,新漫游大厅辅助器,手筋教程(有挂细节)-哔哩哔哩有了最新消息!如...
透视免费!德普之星透视辅助插件... 透视免费!德普之星透视辅助插件,德普之星辅助器(透视)一直是真的挂(有挂教学)-哔哩哔哩在进入德普之...
据统计!hhpoker有透视功... 据统计!hhpoker有透视功能吗,微信小程序雀神广东辅助器,教材教程(确实有挂)-哔哩哔哩1、每一...
透视黑科技!德普之星私人局辅助... 透视黑科技!德普之星私人局辅助免费,德普之星透视(透视)都是是有挂(果真有挂)-哔哩哔哩德普之星私人...
据公告内容!花花生活圈怎么开挂... 据公告内容!花花生活圈怎么开挂,火神大厅辅助,练习教程(有挂技巧)-哔哩哔哩在进入花花生活圈怎么开挂...
透视中牌率!德普之星辅助工具如... 透视中牌率!德普之星辅助工具如何设置,德普之星透视辅助(透视)真是真的有挂(有挂秘笈)-哔哩哔哩1、...
更值得关注的是!新鸿狐挂机,佛... 更值得关注的是!新鸿狐挂机,佛手大菠萝辅助,要领教程(有挂分析)-哔哩哔哩1、佛手大菠萝辅助破解器简...