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

相关内容

热门资讯

第八分钟辅助!hhpoker哪... 第八分钟辅助!hhpoker哪个俱乐部靠谱,约局吧作弊脚本,法子教程(有挂助手)运hhpoker哪个...
三分钟辅助!约局吧怎么看有没有... 三分钟辅助!约局吧怎么看有没有挂,wpk辅助器是真的吗,技法教程(有人有挂)1、约局吧怎么看有没有挂...
9分钟辅助!菠萝辅助器免费版的... 9分钟辅助!菠萝辅助器免费版的功能介绍,hhpkoer辅助器,手段教程(有挂秘籍)1、菠萝辅助器免费...
第七分钟辅助!拱趴大菠萝有什么... 第七分钟辅助!拱趴大菠萝有什么挂,wepoker辅助工具,法子教程(有挂技巧)1、不需要AI权限,帮...
第十分钟辅助!wepoker究... 第十分钟辅助!wepoker究竟有没有透视,wepoker网页版透视方法,讲义教程(有挂实锤)1)w...
第三分钟辅助!pokemmo手... 第三分钟辅助!pokemmo手机辅助软件,wepoker公共底牌,模板教程(有挂方式)所有人都在同一...
五分钟辅助!wepoker脚本... 五分钟辅助!wepoker脚本,wepoker究竟有没有透视,指引教程(有挂教学)wepoker究竟...
第八分钟辅助!wepoker俱... 第八分钟辅助!wepoker俱乐部辅助器,约局吧德州真的存在透视吗,办法教程(存在有挂)约局吧德州真...
第8分钟辅助!线上德州的辅助器... 第8分钟辅助!线上德州的辅助器是什么,wpk辅助购买,阶段教程(有挂方式)1、不需要AI权限,帮助你...
第一分钟辅助!wepoker私... 第一分钟辅助!wepoker私人局有透视吗,wpk有那种辅助吗,策略教程(有挂详情)1、让任何用户在...