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

相关内容

热门资讯

9分钟了解!aapoker透视... 9分钟了解!aapoker透视插件,aapoker能控制牌吗,其实是真的有挂(有挂功能)1、首先打开...
最新研发!wepoker有没有... 最新研发!wepoker有没有透视方法,impoker辅助,总是真的有挂(有挂规律)1、下载好正确养...
科普常识!wepoker游戏的... 科普常识!wepoker游戏的安装教程,wpk免费辅助,其实是真的有挂(有挂教程)1、每一步都需要思...
每日必看推荐!拱趴大菠萝开挂方... 每日必看推荐!拱趴大菠萝开挂方法,hhpoker有作弊的吗,其实是有挂(有挂秘籍)1、实时透视辅助更...
交流学习经验!hhpoker软... 交流学习经验!hhpoker软件可以玩吗,aapoker透视脚本,真是是真的有挂(有挂实锤)1、玩家...
一分钟了解!wejoker辅助... 一分钟了解!wejoker辅助软件,wpk作弊,原来真的有挂(确实有挂)1、起透看视 辅助软件价格2...
重大来袭!fishpoker透... 重大来袭!fishpoker透视,htx矩阵wepoker辅助,竟然真的是有挂(详细教程)1、每一步...
终于知道!hh poker软件... 终于知道!hh poker软件,hhpoker透视工具,原来是真的有挂(有挂秘籍)1、公共底牌简单,...
必备教程!wepokerplu... 必备教程!wepokerplus外挂,wepoker透视脚本免费,好像有挂(有挂解惑)1、进入到是否...
一起来讨论!拱趴大菠萝怎么开挂... 一起来讨论!拱趴大菠萝怎么开挂,wepoker破解游戏盒子,都是是真的有挂(有挂方法)1、许多玩家不...