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

相关内容

热门资讯

最新通报!微乐辅助脚本,来玩a... 最新通报!微乐辅助脚本,来玩app辅助器,详细脚本(的确有挂)1、上手简单,内置详细流程视频教学,新...
今日重大通报!闲逸辅助软件下载... 今日重大通报!闲逸辅助软件下载苹果,四川游戏家园辅助软件下载,详细攻略(有挂攻略)1、四川游戏家园辅...
玩家交流!蜀山挂件辅助,创思维... 玩家交流!蜀山挂件辅助,创思维激k透视插件,详细脚本(有挂方式)运创思维激k透视插件辅助工具,进入游...
一分钟了解!老友麻将辅助器,青... 一分钟了解!老友麻将辅助器,青龙辅助3.0,详细器(有挂解密)1、老友麻将辅助器免费辅助多个强度级别...
一分钟揭秘!先锋脚本辅助,哈局... 一分钟揭秘!先锋脚本辅助,哈局辅助作弊,详细器(了解有挂)暗藏猫腻,小编详细说明先锋脚本辅助破解器有...
如何分辨真伪!丽水茶苑手机辅助... 如何分辨真伪!丽水茶苑手机辅助,蜀山四川小程序破解版,详细方法(竟然有挂)1)蜀山四川小程序破解版免...
推荐一款!UU Games辅助... 推荐一款!UU Games辅助器,江汉晃晃辅助器,详细器(揭秘有挂)亲,关键说明,江汉晃晃辅助器透视...
玩家必看科普!天天微友第三方辅... 玩家必看科普!天天微友第三方辅助软件下载,皮皮辅助器,详细器(了解有挂)1、天天微友第三方辅助软件下...
玩家必看科普!四川途游小程序辅... 玩家必看科普!四川途游小程序辅助,雀神挂件价格骗局,详细方法(有挂教学)1、四川途游小程序辅助公共底...
最新技巧!四川游戏辅助器,小程... 最新技巧!四川游戏辅助器,小程序能开挂吗,详细神器(有挂方式)1、小程序能开挂吗破解器简单,小程序能...