Angular 2 final - change route parameter on the URL programmatically

寵の児 提交于 2019-12-10 12:45:30

问题


Assume I'm actually the page "results"...

http://server/results;dateFrom=03-11-2016;page=1

Me as the results page, I'd like to load the page 2, but I need to set the URL string on the browser to http://server/results;dateFrom=03-11-2016;page=2 just in case if someone decide to bookmark it.

so, how to programmatically change the URL parameter on the Web Browser Address Bar ?

ty !


回答1:


You can do it with this code:

import { Router } from '@angular/router';

...

  constructor(private router: Router) {}

  changeRoute () {
    this.router.navigate(['/results', { dateFrom: this.dateFrom, page: this.page }]);
  }

...

Take a look at this stackblitz demo.


Further information can be found at the API description of router.navigate.



来源:https://stackoverflow.com/questions/40405775/angular-2-final-change-route-parameter-on-the-url-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!