MrNew MrNew - 1 year ago 102
Javascript Question

Angular2 how to do a url query string

I have a search feature on my application which searches a list of products, which is all going okay however I want to redirect the user to another page say

I can only make it

Router navigate
this.router.navigate(['search', {keyword: searchVal}]);
doing this results as;keyword=perfume


const appRoutes: Routes = [
{ path: 'search', component: SearchComponent}

Search function:

findproduct(searchTerm: HTMLInputElement): void {
var searchVal = searchTerm.value;
.subscribe(data => {
this.router.navigate(['search', {keyword: searchVal}]);


How can I make my url to be

Answer Source

You should use queryParams:

this.router.navigate(['/search'], { queryParams: { keyword: searchVal } });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download