Meteor, Iron:Router Passing Multiple Properties on Router.go

前端 未结 1 1270
独厮守ぢ
独厮守ぢ 2021-02-04 13:39

My dilemma is that I would like to pass multiple object properties to an iron:router route in Meteor. The reasoning is that I would like to pass it a property to name my url wi

相关标签:
1条回答
  • 2021-02-04 14:20

    Is the question how to pass multiple parameters to Router.go? Just put all of them in the object for the second parameter:

    Router.go('itemDetails', {_id: 'foo', '_itemId': bar});
    

    Edit:

    Ok, if you want to pass arbitrary values to the url, you can use query paramters:

    Router.go('itemDetails', {itemName: 'foo'}, {query: 'id=bar'});
    

    The id will still be in the url though, it will look like this:

    http://example.com/items/foo?id=bar
    

    And you can retrieve it like this:

    Router.route('/items/:itemName', {
        name: 'itemDetails',
        data: function(){
            return {
                item: Items.findOne(this.params.query.id),
                itemName: this.params.itemName
            };
        }
    );
    
    0 讨论(0)
提交回复
热议问题