Angular懒路由忽略父路径
创始人
2024-10-27 23:01:26
0次

在Angular中,可以通过使用{ path: '', pathMatch: 'full', redirectTo: 'child-route' }来忽略父路径。这样,当导航到父路径时,它会自动重定向到子路径。

下面是一个示例代码:

在父组件的路由模块中(如app-routing.module.ts):

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { ParentComponent } from './parent.component';

const routes: Routes = [
  {
    path: '',
    pathMatch: 'full',
    redirectTo: 'child-route'
  },
  {
    path: 'child-route',
    component: ParentComponent,
    loadChildren: () => import('./child/child.module').then(m => m.ChildModule)
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class ParentRoutingModule { }

在子组件的路由模块中(如child-routing.module.ts):

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { ChildComponent } from './child.component';

const routes: Routes = [
  {
    path: '',
    component: ChildComponent
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class ChildRoutingModule { }

请注意,上述示例假设有一个名为ChildComponent的子组件,其对应的模块为ChildModule。你需要相应地调整和配置你自己的父组件和子组件。

相关内容

热门资讯

教程辅助开挂!雅苑棋牌ai开挂... 很多人使用云端 AI 时,都担心雅苑棋牌、内部资料上传带来隐私风险。这款本地运行的 AI 黑科技,很...
WPK私人局开挂攻略!wepo... WPK私人局开挂攻略!wepoker怎么提高运气,德扑之星ai多功能开挂攻略在进入wepoker怎么...
查到实测辅助!雅苑棋牌ai辅助... 雅苑棋牌AI 游戏攻略黑科技上线本地缓存功能,离线查阅能力开挂。提前下载对应游戏攻略数据包,断网状态...
WPK模拟器透视挂阶段!wep... WPK模拟器透视挂阶段!wepoker破解版内购,aapokerai多功能透视挂软件1、下载好wep...
总算了解辅助器!宝宝麻将ai辅... 总算了解辅助器!宝宝麻将ai辅助器多功能插件,固有真的有辅助器平台大纲主打赛后复盘的 AI 游戏攻略...
WPK控制牌辅助模板!wepo... WPK控制牌辅助模板!wepoker免费脚本弱密码,红龙PoKerai多功能辅助神器在进入wepok...
发现玩家辅助器!逍遥湖北麻将a... 逍遥湖北麻将AI 游戏攻略黑科技上线本地缓存功能,离线查阅能力开挂。提前下载对应游戏攻略数据包,断网...
WPK多开开挂练习!wepok... WPK多开开挂练习!wepoker代打辅助,智星菠萝德州ai多功能开挂工具1、wepoker代打辅助...
普及知识透视!肇源麻将ai透视... 普及知识透视!肇源麻将ai透视多功能插件,好像是真的有透视软件经验AI 是一款可以让一直输的玩家修复...
WPK俱乐部透视大纲!wepo... WPK俱乐部透视大纲!wepoker辅助器安装包定制,智星菠萝德州ai多功能透视神器1、许多玩家不知...