在Iron Router中使用Router.go传递查询参数 [英] Passing query parameters using Router.go in iron router

查看:62
本文介绍了在Iron Router中使用Router.go传递查询参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Router.go中传递查询参数,如下所示:

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

但是这不会更改url,它仍然仅加载当前路径而没有查询字符串.但是,如果我手动将查询参数添加到路径中,例如:

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

这很好用.但是由于我试图用一些经过过滤的数据加载同一页面.因此,反复单击过滤器按钮会一次又一次将过滤器字符串附加到路径.

使用铁路由器传递查询字符串的正确方法是什么?

解决方案

就在文档中

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

上面的JavaScript将导航到该网址:

/post/1?q=s#hashFrag

https://github.com/铁流星/铁路由器/blob/devel/Guide.md#named-routes

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?

解决方案

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

这篇关于在Iron Router中使用Router.go传递查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆