首页 文章

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

提问于
浏览
0

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

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

在我的headerComponent里面我有这个方法

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

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

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

相关问题