简体   繁体   English

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

[英]how to navigates to new Ui component in angular 2?

i am using angular 2 RC 3 and router 3.0.0-alpha.8 and try to navigate to another UI component i am using PathLocationStrategy but it only update url but not UI 我正在使用angular 2 RC 3和路由器3.0.0-alpha.8,并尝试导航到另一个UI组件,我正在使用PathLocationStrategy,但它仅更新url,而不更新UI

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

and inside my headerComponent i have this mathod 在我的headerComponent中,我有这个方法

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

which should navigates to search-listing page but it only update url. 应该会导航到搜索列表页面,但只会更新网址。 在此处输入图片说明

home.routes.ts file: 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 file: app.routes.ts文件:

export const routes: RouterConfig = [
...HomeRoutes,
...UserRoutes,
...ProfileRoutes,
...LandownerRoutes
     ];
  export const APP_ROUTER_PROVIDERS = [
provideRouter(routes),
AUTH_PROVIDERS
      ];

You should use router to navigate 您应该使用路由器导航

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM