如何在角度2中导航到新的Ui组件?

时间:2016-07-15 17:09:17

标签: angular angular2-routing

我正在使用 angular 2 RC 3和路由器3.0.0-alpha.8 并尝试导航到另一个使用 PathLocationStrategy 的UI组件,但它只更新了网址但不是UI

export const HomeRoutes: RouterConfig = [
{path:'search/:searchId',component:SearchListingComponent} ]

并且在我的headerComponent中我有这个mathod

goToSearch(searchId: string): void{
  this.location.go('/search',searchId);}

应该导航到搜索列表页面,但它只更新网址。 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
      ];

1 个答案:

答案 0 :(得分:0)

您应该使用路由器进行导航

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