我正在使用 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);}
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 :(得分:0)
您应该使用路由器进行导航
//in header component
constructor(private router:Router){}
goToSearch(searchId: string): void{
this.router.navigate(['/search',searchId]);}