How to keep query string parameters in URL when accessing a route of an Angular 2 app?

痴心易碎 提交于 2019-11-30 15:42:56

This is fixed in Alpha 41. The query string is now persisted.

Updating for Angular 2:
To preserve query parameters present in the current url, add

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

// Set our navigation extras object
// that contains our global query params

let navigationExtras: NavigationExtras = {
      preserveQueryParams: true
    };   

// Navigate to the login page with extras
this.router.navigate(['/someLink'], navigationExtras);

For more info, check here:

Try this this.router.navigate(['target'], {preserveQueryParams: true});

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