2016-07-15 62 views
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);} 

這應該導航到搜索房源頁面,但它僅更新URL。 enter image description here

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 
     ]; 

回答

0

您應該使用路由器來導航

//in header component 
    constructor(private router:Router){} 
    goToSearch(searchId: string): void{ 
    this.router.navigate(['/search',searchId]);} 
+0

我這樣做,但我有記錄錯誤消息說**錯誤:無法找到主要插座加載'SearchComponent'** – kero

+0

我假設你想要更換主頁路線。您需要在app.routes.ts中定義此路線。你可以詳細說明: –

+0

'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