Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing query parameters using Router.go in iron router

I am trying to pass query parameters in Router.go like below:

var filter = 'abc';
var path = Router.current() && Router.current().path;
Router.go(path, {query: {filter: filter}});

But this does not change the url, it stills loads current path without query string only. But if I add the query parameter manually to path like:

Router.go(path+'?filter='+filter);

this works fine. But since I am trying to load same page with some filtered data. So clicking filter button repeatedly appends the filter string again and again to path.

What is the correct way of passing query string using iron router?

like image 981
Aashu Agarwal Avatar asked Aug 28 '14 13:08

Aashu Agarwal


People also ask

How do you pass Queryparam?

Query parameters can be passed using the Router service or the queryParams directive. To access query parameters ActivatedRoute service needs to be used. Complex data types like arrays of objects can also be passed using query parameters however these data types need to be stringified before being passed.

How we can pass query parameter in URL?

Query parameters are a defined set of parameters attached to the end of a url. They are extensions of the URL that are used to help define specific content or actions based on the data being passed. To append query params to the end of a URL, a '? ' Is added followed immediately by a query parameter.

What is difference between query parameter and URL parameter?

URI parameter (Path Param) is basically used to identify a specific resource or resources whereas Query Parameter is used to sort/filter those resources. Let's consider an example where you want identify the employee on the basis of employeeID, and in that case, you will be using the URI param.

What is Iron router?

Router. A router that works on the server and the browser, designed specifically for Meteor.


1 Answers

Right there in the docs

Router.go('post.show', {_id: 1}, {query: 'q=s', hash: 'hashFrag'});

The above JavaScript will navigate to this url:

/post/1?q=s#hashFrag

https://github.com/iron-meteor/iron-router/blob/devel/Guide.md#named-routes

like image 141
Max Hodges Avatar answered Sep 22 '22 15:09

Max Hodges