You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Angular辅助路由?组件内标签页路由配置问询

配置 Angular 辅助路由以在标签页展示内容

Got it, let's get your auxiliary routing set up so your tab content loads correctly. Based on the routerLink you've already got in app.component.html, here's exactly how to configure variation-margin.routing.module.ts:

Step 1: Import Required Modules & Components

First, make sure you import the Angular router utilities and the components you want to render in each outlet:

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
// Replace these with your actual component imports
import { VariationMarginComponent } from './variation-margin.component';
import { FuturesMarginComponent } from './futures-margin.component';

Step 2: Define the Routes

You need to map both the primary and auxiliary routes. The auxiliary route must explicitly specify the outlet property to match the name in your routerLink:

const routes: Routes = [
  // Primary route for the default/primary outlet
  {
    path: 'variationMargin',
    component: VariationMarginComponent
  },
  // Auxiliary route for the named 'futuresMargin' outlet
  {
    path: 'futuresMargin',
    outlet: 'futuresMargin',
    component: FuturesMarginComponent
  }
];

Step 3: Set Up the Router Module

Since this is a feature module routing file, use RouterModule.forChild() to register the routes:

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

Critical Note: Add the Auxiliary Outlet to Your Template

Don't forget to add the named router outlet in your parent template (likely app.component.html) where you want the futures margin tab content to appear:

<!-- Primary outlet (renders VariationMarginComponent) -->
<router-outlet></router-outlet>

<!-- Auxiliary outlet (renders FuturesMarginComponent) -->
<router-outlet name="futuresMargin"></router-outlet>

How It Works

Your routerLink [{outlets:{primary:'variationMargin', futuresMargin:'futuresMargin'}}] tells Angular to:

  • Load the variationMargin route into the default (primary) outlet
  • Load the futuresMargin route into the named futuresMargin outlet

By defining the auxiliary route with the outlet property in your routing module, Angular knows exactly where to render each component.

Just double-check that:

  • Your component imports are correct
  • The route path values match exactly what's in your routerLink (Angular routing is case-sensitive)
  • You've imported VariationMarginRoutingModule into your feature module or root app module

内容的提问来源于stack exchange,提问作者Anand

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:51:40