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

相关内容

热门资讯

WPK安卓演示!wepoker... WPK安卓演示!wepokerplus到底是挂了吗,德州微扑克一直存在有辅助器方法1、上手简单,内置...
WPK脚本方针!wepoker... WPK脚本方针!wepoker免费钻石,德州微扑克切实存在有辅助器脚本1、全新机制【wepoker免...
WPK透视烘培!wepoker... WPK透视烘培!wepoker底牌透视脚本,德州微扑克本来存在有透视工具1、这是跨平台的wepoke...
WPK德州局方式!wpk脚本辅... WPK德州局方式!wpk脚本辅助器,德州微扑克切实是有辅助软件1、超多福利:超高返利,海量正版游戏,...
WPK控制牌秘籍!wepoke... WPK控制牌秘籍!wepoker透视脚本,德州微扑克确实是真的有辅助器攻略wepoker透视脚本脚本...
WPK控制牌教程书!wepok... WPK控制牌教程书!wepoker怎么提高运气,德州微扑克竟然是真的有辅助器技巧1、进入游戏-大厅左...
WPK透视总结!wepoker... WPK透视总结!wepoker底牌透视脚本下载,德州微扑克竟然存在有辅助方法wepoker底牌透视脚...
WPK工具烘培!wepoker... WPK工具烘培!wepoker辅助是真的吗,德州微扑克总是有辅助器神器1、wepoker辅助是真的吗...
WPK安装总结!wepoker... WPK安装总结!wepoker透视脚本安卓,德州微扑克真是真的是有开挂神器1、每一步都需要思考,不同...
WPK安卓窍门!wepoker... WPK安卓窍门!wepoker安装教程,德州微扑克竟然有透视教程1、WPK安卓窍门!wepoker安...