伙計,您知道為什么當我重新加載頁面時有角度地重復我的主端點。
當我第一次加載我的頁面時一切正常,在 URL 中設定了主端點,但是當我在 url 中重新加載頁面時,又添加了另一個 /home。
在重新加載頁面之前: http://localhost:4200/home
重新加載頁面后: http://localhost:4200/home/home
這是我的 appRoutes
import { Route } from "@angular/router";
export const AppRoutes:Route[] = [
{
path:'', redirectTo:'home', pathMatch:'full'
},
{
path:'home', loadChildren: ()=> import("./modules/home/home.module").then(m=>m.HomeModule)
}
]
我在我的 appModule 中匯入這個檔案
RouterModule.forRoot(AppRoutes)
這是我的家庭路線檔案
import { Route } from "@angular/router";
import { HomeComponent } from "./home.component";
export const HomeRoutes:Route[] = [
{
path:'',
component:HomeComponent
}
]
我將此檔案匯入我的 HomeModule
RouterModule.forChild(HomeRoutes)
uj5u.com熱心網友回復:
在index.html中添加
<base href="/">而不是<base href="">如果它不存在。如果沒有幫助,請嘗試打開路由跟蹤和除錯。
RouterModule.forRoot( AppRoutes, { enableTracing: true } // <-- 僅用于除錯目的)
uj5u.com熱心網友回復:
您的路由配置是正確的。
下面的這個鏈接是根據您的配置在 stackblitz 中創建的。
點擊這里
你必須在其他地方找到你的問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/516431.html
標籤:有角度的
