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

相关内容

热门资讯

外挂模块!约局吧德州有挂吗,佛... 外挂模块!约局吧德州有挂吗,佛手大菠萝13道挂哪里-一直真的是有辅助脚本(哔哩哔哩)1.佛手大菠萝1...
外挂指南!佛手在线有挂吗,大菠... 外挂指南!佛手在线有挂吗,大菠萝免费辅助-本来是有辅助脚本(哔哩哔哩)1、首先打开大菠萝免费辅助辅助...
外挂技法!德普之星辅助工具如何... 外挂技法!德普之星辅助工具如何打开,拱趴大菠萝开挂方法-原来一直都是有辅助脚本(哔哩哔哩)1、让任何...
外挂教材!pokernow辅助... 外挂教材!pokernow辅助工具,德州透视是真的吗-一贯是有辅助工具(哔哩哔哩)1、德州透视是真的...
外挂绝活!德扑之心免费透视,佛... 外挂绝活!德扑之心免费透视,佛手在线大菠萝技巧-真是是有辅助app(哔哩哔哩)1、进入到佛手在线大菠...
外挂手筋!德州圈脚本,菠萝辅助... 外挂手筋!德州圈脚本,菠萝辅助器免费版的特点-本来有辅助插件(哔哩哔哩)1、很好的工具软件,可以解锁...
外挂练习!德扑之心免费透视,拱... 您好,拱趴大菠萝万能辅助器这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很...
外挂手筋!poker worl... 外挂手筋!poker world辅助,聚星ai辅助工具收费多少-好像存在有辅助技巧(哔哩哔哩)外挂手...
外挂绝活儿!werplan辅助... 外挂绝活儿!werplan辅助软件,德普之星辅助器-一直真的有辅助插件(哔哩哔哩)1、werplan...
外挂模块!约局吧德州真的存在透... 外挂模块!约局吧德州真的存在透视吗,竞技联盟辅助-总是存在有辅助app(哔哩哔哩)1、约局吧德州真的...