How to hide empty or undefined query parameters in angular 2?
I'm using Angular2 (RC2) and the new Router (Alpaha.8) How can I stop a query param showing in the URL if it is undefined? Eg.
this.router.navigate(["/results", this.month, this.day],
{
queryParams: {
adults: +this.adults
}
});
Sometimes adults may have a value and other times it may not which is when I don't want to show it.
I don't think there is another way than just not to add them when they are undefined:
let queryParams:any = {};
if(this.adults) queryParams.adults = this.adults;
this.router.navigate(["/results", this.month, this.day],
{
queryParams: queryParams
}
});