我知道如何导航添加其他参数到路由器,例如:
@H_403_20@解决方法
this._router.navigate(['/users',{ page: 2 }]);
将导致导航到/ users; page = 2.
只需使用router.navigate()方法.路由器将识别您要求导航到同一组件,因此它将更改参数而不实际导航.
要获得新参数的通知并更新UI,您可以订阅ActivatedRoute.params Observable:
import {ActivatedRoute} from '@angular/router'; ... constructor(private route:ActivatedRoute){} ngOnInit() { this.sub = this.route.params.subscribe(params => { let page = +params['page']; // (+) converts string 'id' to a number let sort = params['sort'] || 'ASC'; //use ASC order if none is supplied this.updateUI(page,sort);//function would update component as you wish }); }
搜索params.subscribe on this page获取更多信息.