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、首先打开微乐自建房...
热门推荐!微乐小程序插件免费(... 热门推荐!微乐小程序插件免费(透视器),微乐安徽麻将一直是有透视挂app在进入微乐小程序插件免费软件...
实测揭晓!微信小程序微乐辅助器... 实测揭晓!微信小程序微乐辅助器破解版(开挂),微乐提坑竟然有透视挂脚本1、超多福利:超高返利,海量正...
必备辅助推荐!微乐家乡破解版(... 必备辅助推荐!微乐家乡破解版(开挂),微乐长春麻将本来真的是有透视挂软件1、这是跨平台的微乐家乡破解...
程序员教你!微乐广西麻辣(作弊... 程序员教你!微乐广西麻辣(作弊器),微乐长沙跑胡子都是真的是有透视挂攻略微乐广西麻辣透视方法中分为三...
一分钟快速了解!小程序微乐斗地... 一分钟快速了解!小程序微乐斗地主辅助(透视挂),微乐保皇一直真的是有透视挂方法1)小程序微乐斗地主辅...