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。你需要相应地调整和配置你自己的父组件和子组件。

相关内容

热门资讯

德扑起手牌胜率图!德州之星有外... 德扑起手牌胜率图!德州之星有外挂,(wepoKE)果然存在有挂,专业教程(有挂技巧);1、每一步都需...
透视了解!aapoker透视插... 透视了解!aapoker透视插件下载,wpk辅助软件,科普(有挂攻略)进入游戏-大厅左侧-新手福利-...
wpk提高胜率!德扑之星猫腻,... wpk提高胜率!德扑之星猫腻,(WePoKer)切实真的是有挂,攻略教程(有挂解说)1、任何德扑之星...
透视中牌率!aapoker可以... 透视中牌率!aapoker可以开挂吗,hhpoker辅助软件,我来教教大家(有挂黑科技)1、构建自己...
aapoker外挂!aa扑克辅... aapoker外挂!aa扑克辅助,(wepoker)本来是有挂,安装教程(有挂黑科技)1、aa扑克辅...
透视最新!hhpoker万能辅... 透视最新!hhpoker万能辅助器,aapoker辅助器怎么用,玩家必看科普(有挂透明);小薇(透视...
wepokeai代打!wepo... wepokeai代打!wepokeai代打,(wePOke)真是有挂,安装教程(有挂脚本)1、wep...
透视科技!aapoker辅助插... 透视科技!aapoker辅助插件工具下载,wepoker透视脚本苹果,科技通报(有挂规律)1)aap...
wepoke有辅助挂!微扑克辅... wepoke有辅助挂!微扑克辅助机器人,(WePoKer)本来有挂,专业教程(有挂教程)1、在微扑克...
透视挂!wepoker透视版下... 透视挂!wepoker透视版下载,aapoker辅助插件工具,揭秘关于(有挂介绍)1、下载好aapo...