0
我使用角2 RC 3和路由器3.0.0-alpha.8並嘗試導航到我使用PathLocationStrategy另一個UI組件,但它僅更新網址而不是UI如何在角度2中導航到新的UI組件?
export const HomeRoutes: RouterConfig = [
{path:'search/:searchId',component:SearchListingComponent} ]
和我headerComponent裏面我有這個馬託
goToSearch(searchId: string): void{
this.location.go('/search',searchId);}
home.routes.ts文件:
export const HomeRoutes: RouterConfig = [
{ path: '', component: HomeComponent },
{ path: 'home', component: HomeComponent },
{ path: 'search', component: SearchComponent },
{path:'search/:searchId',component:SearchListingComponent},
{ path: 'listing/:id', component: ListingPageComponent}
]
app.routes.ts文件:
export const routes: RouterConfig = [
...HomeRoutes,
...UserRoutes,
...ProfileRoutes,
...LandownerRoutes
];
export const APP_ROUTER_PROVIDERS = [
provideRouter(routes),
AUTH_PROVIDERS
];
我這樣做,但我有記錄錯誤消息說**錯誤:無法找到主要插座加載'SearchComponent'** – kero
我假設你想要更換主頁路線。您需要在app.routes.ts中定義此路線。你可以詳細說明: –
'export const HomeRoutes:RouterConfig = {{'path,'search',component:path'',component:HomeComponent}, {path:'home',component:HomeComponent}, { SearchComponent}, {path:'search /:searchId',component:SearchListingComponent}, {path:'listing /:id',component:ListingPageComponent} – kero