[英]Angular Routing changes the page
I would like to go to another page, for that I use Angular routing but the routing does not work,我想转到另一个页面,为此我使用了 Angular 路由,但路由不起作用,
I stay on the same page and the text which should be displayed on the other page (payment Component) is displayed on my (main component) why ?我停留在同一页面上,而应该在其他页面(支付组件)上显示的文本显示在我的(主要组件)上,为什么?
app.routing.module.ts app.routing.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { MainComponent } from './main/main.component';
import { PaymentComponent } from './payment/payment.component';
const routes: Routes = [
{ path: 'main', component: MainComponent },
{ path: 'payment', component: PaymentComponent },
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
export const routingComponents = [MainComponent, PaymentComponent];
here in header component when I click I would like to go to the Payment component page在标题组件中,当我单击时,我想转到付款组件页面
header.component.html头文件.component.html
<div class="nav-content">
<div>
<div class="top-nav">
<h1>E-Book Store</h1>
<div class="top-nav-search">
<div class="shopping-button">
<a routerLink="payment" routerLinkActive="active">
<button type="submit" class="icon">Mon Panier</button>
</a>
</div>
</div>
</div>
</div>
<div class="header-content"></div>
</div>
app.component.html应用程序组件.html
<app-main></app-main>
<router-outlet></router-outlet>
You should remove <app-main></app-main>
from your app.component.html
, since that main component is bound to specific route and should not be visible all the time.您应该从
app.component.html
删除<app-main></app-main>
,因为该主要组件绑定到特定路由并且不应该一直可见。
After you remove it, the main component
should be available by /main
path, and payment component
by /payment
path.删除后,
main component
应该可以通过/main
路径使用,而payment component
应该可以通过/payment
路径使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.