Angular 角度路由片段替换完整的URL路径

Angular 角度路由片段替换完整的URL路径,angular,angular-routing,angular-router,Angular,Angular Routing,Angular Router,我试图使用ng引导为导航标签使用角度9路线片段,并参考了这一点。问题是在添加“单击”选项卡时,它正在替换整个URL路径,例如,路径应该与单击“选项卡”后相同,但它正在形成,它正在完全替换/home路径 及 HTML 平板电脑 export class FlatTab { tabId: number; name: string; active: boolean; } 提前感谢您的app-routing.module.ts应该有以下代码:- import { NgModul

我试图使用ng引导为导航标签使用角度9路线片段,并参考了这一点。问题是在添加“单击”选项卡时,它正在替换整个URL路径,例如,路径应该与单击“选项卡”后相同,但它正在形成,它正在完全替换/home路径

HTML

平板电脑

export class FlatTab {
    tabId: number;
    name: string;
    active: boolean;
}

提前感谢

您的app-routing.module.ts应该有以下代码:-

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './home/home.component';


const routes: Routes = [
  {path: '', pathMatch: 'full', redirectTo: 'home'},
  {path: 'home', component: HomeComponent}
  ];

@NgModule({
  imports: [RouterModule.forRoot(routes, {
    initialNavigation: 'enabled'
  })],
  exports: [RouterModule]
})
export class AppRoutingModule { }
<ul ngbNav [activeId]="route.fragment | async" class="nav-tabs justify-content-center container-lg">
    <li [ngbNavItem]="flatTab.name" *ngFor="let flatTab of flatTabs">
        <a ngbNavLink routerLink="home" [fragment]="flatTab.name"
         [class.active]="flatTab.active" (click)="activateTab(flatTab)">{{ flatTab.name }}</a>
    </li>
</ul>
您的home.component.html应包含以下代码:-

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './home/home.component';


const routes: Routes = [
  {path: '', pathMatch: 'full', redirectTo: 'home'},
  {path: 'home', component: HomeComponent}
  ];

@NgModule({
  imports: [RouterModule.forRoot(routes, {
    initialNavigation: 'enabled'
  })],
  exports: [RouterModule]
})
export class AppRoutingModule { }
<ul ngbNav [activeId]="route.fragment | async" class="nav-tabs justify-content-center container-lg">
    <li [ngbNavItem]="flatTab.name" *ngFor="let flatTab of flatTabs">
        <a ngbNavLink routerLink="home" [fragment]="flatTab.name"
         [class.active]="flatTab.active" (click)="activateTab(flatTab)">{{ flatTab.name }}</a>
    </li>
</ul>

    你好,阿卡什,谢谢你的回复。根据文档()它应该是“.”(我也更新了问题),但我两个都累了,但都不起作用。stackblitz请?给stackblitz,只有我能帮助我配置它。Aakash这是编辑URL,你必须导航“/home”,就像它是一个路由配置问题一样,我能够理解如何处理URL中的片段