Remove a parameter from queryParams angular 2 -


i navigate page in app query parameter. after parameter url want delete it, ideally have this:

let usertoken: string;     this.sub = this.router       .routerstate       .queryparams       .subscribe(params => {         usertoken = params['token'];         params['token'].remove();       }); 

but remove function doesn't exist. have alternative?

just in case people find thread (like did). have scenario receive jwt token in query string (/login?jwt=token). needed fetch token (and store etc), needed make sure got safely removed url. reloading login route (by using this.router.navigate(['login']) works in principe, however, user can use browser button, replaying token login.

i solved not using navigate di'ing 'location' service (from @angular/common). service has 'replacestate' method, removes token history wel url

 this.location.replacestate('login') 

hope helps someone.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -