Passing query parameters using Router.go in iron router

前端 未结 4 1262
北海茫月
北海茫月 2021-02-08 14:08

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,         


        
相关标签:
4条回答
  • 2021-02-08 14:48

    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

    0 讨论(0)
  • 2021-02-08 14:48

    The parameters are Router.go(path, params, options). The query part should go in the options parameter, so try the following: Router.go(path, {}, {query: {filter: 'filter='+filter}}).

    EDIT

    Answer updated according to Robins comment below.

    0 讨论(0)
  • 2021-02-08 14:59

    Try this:

    var path = Router.current() && Router.current().route.originalPath;
    

    That should give you the path without the query string attached.

    0 讨论(0)
  • 2021-02-08 15:04

    I found that if your first parameter in Router.go is a path, instead of a template name, the query filter is not passed. Use a template name:

    Router.go(templatename, {_id: 1}, {query: 'q=s', hash: 'hashFrag'}); 
    
    0 讨论(0)
提交回复
热议问题