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

相关内容

热门资讯

透视实锤!荔枝竞技辅助,hhp... 透视实锤!荔枝竞技辅助,hhpoker辅助挂(辅助挂)详细开挂辅助安装;打开点击测试直接进入微信(1...
透视透明!财神十三脚本,wep... 大家好,今天小编来为大家解答wepoker辅助器免费这个问题咨询软件客服可以免费测试直接加微信(13...
透视透明挂!财神13辅助包最新... >>您好:财神13辅助包最新版本更新内容详解确实是有挂的,很多玩家在这款财神13辅助包最新版本更新内...
透视数据!werplan辅助软... 透视数据!werplan辅助软件,wepoker作弊辅助(辅助挂)详细开挂辅助神器;无需打开直接搜索...
透明安装!欢聚水鱼脚本,wep... 透明安装!欢聚水鱼脚本,wepoker破解器激活码(辅助挂)详细开挂辅助挂;亲,wepoker破解器...
透明透视!wepoker免费脚... 透明透视!wepoker免费脚本,aapoker怎么提高中牌率(辅助挂)详细开挂辅助神器;打开点击测...
透明辅助!逍遥辅助器怎么用,w... 大家好,今天小编来为大家解答逍遥辅助器怎么用这个问题咨询软件客服可以免费测试直接加微信(136704...
透视游戏!黑科技软件大全,we... 【亲,wepoker私人局辅助挂 这款游戏可以开挂的,确实是有挂的,很多玩家在这款wepoker私人...
透明挂透视!威信茶馆有挂的吗,... 透明挂透视!威信茶馆有挂的吗,wepoker辅助器安装包(辅助挂)详细开挂辅助工具;无需打开直接搜索...
透视能赢!wepoker到底有... 透视能赢!wepoker到底有没有透视,哈糖大菠萝挂法(辅助挂)详细开挂辅助安装;打开点击测试直接进...