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

相关内容

热门资讯

透视教程!德普之星辅助软件,德... 透视教程!德普之星辅助软件,德普辅助软件,方针教程(原来是有挂)-哔哩哔哩1、很好的工具软件,可以解...
透视存在!we poker插件... 透视存在!we poker插件(透视)开挂辅助攻略(一直真的有挂)-哔哩哔哩所有人都在同一条线上,像...
透视规律!wpk官网下载链接,... 透视规律!wpk官网下载链接,佛手在线大菠萝为什么都输,手段教程(好像是有挂)-哔哩哔哩透视规律!w...
透视靠谱!黑侠破解wepoke... 透视靠谱!黑侠破解wepoker(透视)开挂辅助app(切实真的是有挂)-哔哩哔哩1、黑侠破解wep...
透视系统!德扑圈透视,德州局透... 透视系统!德扑圈透视,德州局透视,要领教程(一贯存在有挂)-哔哩哔哩;1、该软件可以轻松地帮助玩家将...
透视机器人!wepoker私人... 透视机器人!wepoker私人局透视教程(透视)开挂辅助挂(都是真的有挂)-哔哩哔哩1、玩家可以在w...
透视智能ai!wepoker私... 透视智能ai!wepoker私人局俱乐部怎么进,wepoker透视有用吗,练习教程(一贯是真的挂)-...
透视神器!wepoker插件功... 透视神器!wepoker插件功能辅助器(透视)开挂辅助技巧(好像是真的挂)-哔哩哔哩暗藏猫腻,小编详...
透视工具!wepoker底牌透... 透视工具!wepoker底牌透视,wpk透视工作室,妙招教程(一贯真的有挂)-哔哩哔哩透视工具!we...
透视数据!wepoker游戏的... 透视数据!wepoker游戏的安装教程(透视)开挂辅助方法(本来是真的挂)-哔哩哔哩运wepoker...