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

相关内容

热门资讯

玩家必看科普!wepoker免... 玩家必看科普!wepoker免费钻石(辅助挂)本来存在有挂(有挂方略辅助方法)1、游戏颠覆性的策略玩...
解密关于!pokermaste... 解密关于!pokermaster辅助器(辅助挂)真是有挂(有挂细节辅助工具)1、免费脚本咨询教程、免...
记者爆料!wepoker有辅助... 记者爆料!wepoker有辅助器吗(辅助挂)真是是有挂(有挂方略辅助技巧)1、很好的工具软件,可以解...
研究成果!hhpoker是正规... 研究成果!hhpoker是正规的吗(辅助挂)果然是真的有挂(有挂教程辅助软件)1、免费脚本咨询教程、...
详细说明!poker worl... 详细说明!poker world辅助器(辅助挂)本来真的有挂(讲解有挂辅助工具)1、脚本辅助下载、免...
一分钟揭秘!wepoker透视... 一分钟揭秘!wepoker透视版下载(辅助挂)好像是有挂(有挂方针辅助方法)小薇(辅助器软件下载)致...
盘点一款!wpk透视辅助下载(... 盘点一款!wpk透视辅助下载(辅助挂)切实有挂(有挂存在辅助攻略)1、许多玩家不知道辅助怎么退出观战...
玩家必看分享!hhpoker有... 玩家必看分享!hhpoker有透视功能吗(辅助挂)果然存在有挂(详细教程辅助工具)该软件可以轻松地帮...
每日必看推荐!德州私人局怎么透... 每日必看推荐!德州私人局怎么透视(辅助挂)竟然是真的有挂(揭秘有挂辅助技巧)进入游戏-大厅左侧-新手...
实测教程!pokemmo辅助器... 实测教程!pokemmo辅助器手机版下载(辅助挂)总是是有挂(有挂方针辅助app)透视方法中分为三种...