我的页面上有一个带有某些选项的侧边栏,单击这些选项后,我想在新页面中重定向。
当我单击它时,我有一个名为“定价详细信息”的选项,应该打开一个新页面,并在URL的末尾添加/ pricing。尽管URL正在更新,但是新页面无法打开。
这是我的app.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { PricingComponent } from './pricing/pricing.component';
const routes: Routes = [{ path: 'pricing', component: PricingComponent}];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
这是带有“定价”部分的HTML部分
<li class="sub-menu" name="idk">
<a routerLink='/pricing'>
<span>Pricing Details</span>
</a>
</li>
这是我的app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { SidebarComponent } from './sidebar/sidebar.component';
import { NavbarComponent } from './navbar/navbar.component';
import { HomeComponent } from './home/home.component';
import { PricingComponent } from './pricing/pricing.component';
import { EstimateComponent } from './estimate/estimate.component';
import { AccountComponent } from './account/account.component';
@NgModule({
declarations: [
AppComponent,
SidebarComponent,
NavbarComponent,
HomeComponent,
PricingComponent,
EstimateComponent,
AccountComponent
],
imports: [
BrowserModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
当我单击价格详细信息时,URL正在更新,但仍在同一页面上。
答案 0 :(得分:0)
确保在<router-outlet></router-outlet>
html模板中包含AppComponent