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?
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.
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.
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.
Router. A router that works on the server and the browser, designed specifically for Meteor.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With