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

相关内容

热门资讯

推荐几款新版辅助攻略!青橙竞技... 推荐几款新版辅助攻略!青橙竞技多功能辅助攻略,青橙竞技真是真的有辅助攻略1、青橙竞技破解器简单,青橙...
技术分享作弊器教程!禾沐多功能... 技术分享作弊器教程!禾沐多功能作弊器教程,禾沐都是真的有作弊器教程1、禾沐有没有辅助教程、禾沐有透视...
盘点一款辅助器技巧!廊坊麻将多... 盘点一款辅助器技巧!廊坊麻将多功能辅助器技巧,廊坊麻将其实存在有辅助器技巧1、下载好廊坊麻将正确养号...
教程辅助作弊器教程!友乐广西麻... 教程辅助作弊器教程!友乐广西麻将多功能作弊器教程,友乐广西麻将真是是有作弊器教程1、进入到友乐广西麻...
每日必看推荐透视器攻略!奉化冲... 每日必看推荐透视器攻略!奉化冲刺多功能透视器攻略,奉化冲刺好像真的是有透视器攻略暗藏猫腻,小编详细说...
推荐一款开挂软件!大宝麻将多功... 推荐一款开挂软件!大宝麻将多功能开挂软件,大宝麻将一贯是真的有开挂软件大宝麻将脚本下载中分为三种模型...
玩家攻略透视挂脚本!优优龙岩麻... 玩家攻略透视挂脚本!优优龙岩麻将多功能透视挂脚本,优优龙岩麻将总是有透视挂脚本1、下载好优优龙岩麻将...
揭秘真相辅助脚本!打两圈泰州麻... 揭秘真相辅助脚本!打两圈泰州麻将多功能辅助脚本,打两圈泰州麻将真是有辅助脚本暗藏猫腻,小编详细说明打...
终于知道透视器方法!打两圈兴化... 终于知道透视器方法!打两圈兴化麻将多功能透视器方法,打两圈兴化麻将总是有透视器方法1、任何打两圈兴化...
发现玩家透视挂方法!哈哈长沙麻... 发现玩家透视挂方法!哈哈长沙麻将多功能透视挂方法,哈哈长沙麻将总是真的有透视挂方法1、点击下载安装,...