我的專案是這樣呈現的
app> home> mark>opel

當用戶點擊歐寶超鏈接時,該頁面不會運行...

在 home.component.html 頁面,我有這個: 我們同意路徑是正確的嗎?
<ul>
<li><a routerLink="mark/opel">Opel</a></li>
</ul>
<router-outlet></router-outlet>
我不明白為什么歐寶頁面的內容不見了?
opel.component.html
<h1>Opel page</h1>
我的代碼在這里
非常感謝您的幫助。
uj5u.com熱心網友回復:
擁有良好的代碼結構(目錄、命名等)對于維護和進一步開發很重要,但該結構不一定代表路由結構。
路由的重要內容是定義的路由,而您缺少到OpelComponent.
要使您的應用程式正常作業,您需要opel在MarkRoutingModule.
添加路線后,您MarkRoutingModule將如下所示:
const routes: Routes = [
{
path: '',
component: MarkComponent,
},
{
path: 'opel', // <- This route here was missing
component: OpelComponent
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class MarkRoutingModule {}
uj5u.com熱心網友回復:
在應用程式的當前結構中,您必須明確地將路徑映射opel到OpelComponent.
看一下調整后的代碼
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/398520.html
