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

相关内容

热门资讯

六分钟模板!大菠萝辅助器(透视... 六分钟模板!大菠萝辅助器(透视)其实真的有辅助工具(哔哩哔哩)运大菠萝辅助器辅助工具,进入游戏界面。...
第8分钟办法!wepoker透... 第8分钟办法!wepoker透视脚本(透视)原来真的是有辅助开挂(哔哩哔哩)1、wepoker透视脚...
第二分钟积累!newpoker... 第二分钟积累!newpoker脚本(透视)果然存在有辅助工具(哔哩哔哩)newpoker脚本透视方法...
第4分钟攻略!德州来玩辅助器(... 第4分钟攻略!德州来玩辅助器(透视)本来真的有辅助下载(哔哩哔哩)小薇(辅助器软件下载)致您一封信;...
6分钟绝活儿!aapoker怎... 6分钟绝活儿!aapoker怎么控制牌(透视)好像有辅助开挂(哔哩哔哩)1、aapoker怎么控制牌...
七分钟指南书!aapoker破... 七分钟指南书!aapoker破解侠是真的吗(透视)原来存在有辅助教程(哔哩哔哩)暗藏猫腻,小编详细说...
第3分钟法门!智星德州插件(透... 第3分钟法门!智星德州插件(透视)好像真的有辅助辅助(哔哩哔哩)1、下载好智星德州插件脚本下载之后点...
1分钟机巧!wepoker到底... 1分钟机巧!wepoker到底有没有透视(透视)果然是有辅助开挂(哔哩哔哩)1、下载好wepoker...
7分钟学习!wepoker养号... 7分钟学习!wepoker养号规律(透视)总是有辅助辅助(哔哩哔哩)1)wepoker养号规律免费钻...
三分钟秘籍!hhpoker是真... 三分钟秘籍!hhpoker是真的假的(透视)都是是有辅助脚本(哔哩哔哩)1、操作简单,无需hhpok...