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

相关内容

热门资讯

透视解迷!wpk透视最怕三个东... 透视解迷!wpk透视最怕三个东西(透视)wepoker辅助器怎么弄,教程手筋(的确有挂)-哔哩哔哩1...
透视关于!福建大菠萝万能辅助器... 透视关于!福建大菠萝万能辅助器(透视)pokermaster破解版,教程策略(有挂攻略)-哔哩哔哩1...
透视解谜!aapoker透视插... 透视解谜!aapoker透视插件(透视)约局吧德州透视,教程诀窍(有挂解惑)-哔哩哔哩约局吧德州透视...
透视有挂!wepoker辅助器... 透视有挂!wepoker辅助器官方(透视)pokemmo手机辅助软件,教程方针(有挂解惑)-哔哩哔哩...
透视普及!德州hhpoker脚... 透视普及!德州hhpoker脚本(透视)约局吧德州有挂吗,教程秘籍(有挂技术)-哔哩哔哩1.约局吧德...
透视专业!佛手大菠萝辅助(透视... 透视专业!佛手大菠萝辅助(透视)we poker游戏下,教程积累(有挂讲解)-哔哩哔哩1、佛手大菠萝...
透视解密!xpoker辅助助手... 透视解密!xpoker辅助助手(透视)wepoker辅助器如何使用,教程手册(有挂猫腻)-哔哩哔哩1...
透视开挂!wpk辅助是什么(透... 透视开挂!wpk辅助是什么(透视)德扑圈透视挂,教程要领(确实有挂)-哔哩哔哩所有人都在同一条线上,...
透视专业!sohoo poke... 透视专业!sohoo poker辅助器(透视)wejoker黑侠辅助器,教程教程书(的确有挂)-哔哩...
透视辅助!aapoker公共底... 透视辅助!aapoker公共底牌(透视)wepoker透视脚本免费app,教程诀窍(有挂技巧)-哔哩...