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、吉祥麻将辅助软件下载优化,吉祥麻...
我来教大家!PX在线透视挂脚本... 我来教大家!PX在线透视挂脚本软件,PX在线好像真的是有透视挂详情工具PX在线透视方法中分为三种模型...
今日百科!天天遇难麻将透视脚本... 今日百科!天天遇难麻将透视脚本软件,天天遇难麻将总是有透视科普工具1、操作简单,无需天天遇难麻将手机...
科普常识!爱玩麻将辅助脚本软件... 科普常识!爱玩麻将辅助脚本软件,爱玩麻将其实存在有辅助揭幕app1、实时爱玩麻将透视辅助更新:用户可...
我来教教大家!云雀麻将辅助器脚... 我来教教大家!云雀麻将辅助器脚本软件,云雀麻将竟然存在有辅助器关于脚本1、云雀麻将公共底牌简单,云雀...
关于!雀友汇透视脚本软件,雀友... 关于!雀友汇透视脚本软件,雀友汇真是真的是有透视解迷方法1、下载好雀友汇脚本下载之后点击打开,先需要...
玩家必用!乐友透视脚本软件,乐... 玩家必用!乐友透视脚本软件,乐友果然是真的有透视普及方法1、完成乐友有辅助插件,帮助玩家取得所有比赛...