Angular命名的路由出口不如预期工作
创始人
2024-10-28 13:01:01
0

案例代码如下,其中app-routing.module.ts是Angular的路由模块文件,app.component.html是应用的根组件模板文件。

app-routing.module.ts:

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { HomeComponent } from './home/home.component';
import { AboutComponent } from './about/about.component';
import { NotFoundComponent } from './not-found/not-found.component';

const routes: Routes = [
  { path: '', redirectTo: '/home', pathMatch: 'full' },
  { path: 'home', component: HomeComponent, outlet: 'main' },
  { path: 'about', component: AboutComponent, outlet: 'main' },
  { path: '**', component: NotFoundComponent }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

app.component.html:



在上面的代码中,我们定义了两个router-outlet,一个是默认的出口,另一个是命名为main的出口。路由配置中的outlet属性指定了每个路由对应的出口。

在模板文件app.component.html中,我们使用了两个router-outlet,分别用于显示默认的路由和命名为main的路由。

这样,当路由匹配到home路径时,HomeComponent会在默认的router-outlet中显示,当路由匹配到about路径时,AboutComponent会在命名为mainrouter-outlet中显示。

如果没有匹配的路由,会显示NotFoundComponent

这样,我们就可以根据需要在不同的路由出口中显示不同的组件。

相关内容

热门资讯

不少玩家反映!wepoker有... 不少玩家反映!wepoker有没有挂,德普之星透视辅助软件是真的吗,果然确实有挂(果真有挂)亲,关键...
此事引发广泛关注!we-pok... 此事引发广泛关注!we-poker辅助,德普之星辅助软件,本来是有挂(的确有挂)1、全新机制【德普之...
截至目前!sohoo开挂辅助,... 截至目前!sohoo开挂辅助,德扑圈透视挂,切实真的有挂(证实有挂)1、德扑圈透视挂脚本辅助下载、德...
今天下午!wepoker透视脚... 今天下午!wepoker透视脚本免费,德扑之星的辅助工具介绍,都是是有挂(有挂技术)1、每一步都需要...
今天上午!wepokerplu... 今天上午!wepokerplus透视脚本免费,德普之星透视软件免费入口官网,原来存在有挂(有挂存在)...
经调查!wepoker有没有辅... 经调查!wepoker有没有辅助,德扑之星私人局辅助器,都是真的有挂(有挂分享)1.德扑之星私人局辅...
针对!wepoker私人局怎么... 针对!wepoker私人局怎么玩,德扑之星有透视辅助吗,果然真的是有挂(有挂教学)在进入德扑之星有透...
据相关数据显示!wepoker... 据相关数据显示!wepoker私人局辅助器怎么用,德普辅助器怎么用,总是真的有挂(有挂规律)德普辅助...
出现新变化!德州圈脚本,德扑之... 出现新变化!德州圈脚本,德扑之星有透视辅助吗,一贯真的是有挂(详细教程);1、下载好德扑之星有透视辅...
今年以来!wepoker破解器... 今年以来!wepoker破解器激活码,智星德州插件最新版本更新内容详解,一贯真的有挂(揭秘有挂)1、...