Mongo query in FlowRouter route

Hello. I have a collection of items.

The app is just make query on collection and render selected items. I want just qet query from route param and directly pass it to find:

Template.itemsList.helpers({
  items: () => {
    let filter = FlowRouter.getQueryParam('filter') || {};
    return items.find(filter);
  }
}

The one of valid query is:

items.find({'maps.10': true})

So let’s say I want to render such an items. I set params (on checkbox click e.g.):

FlowRouter.setQueryParams({filter: {'maps.11': true}})

URL now looks like what we want:

http://localhost:3000/?filter%5Bmaps.11%5D=true

I expect then when i do FlowRouter.getQueryParam('filter') I’ll get {'maps.11': true}. But let’s try:

FlowRouter.getQueryParam('filter')
//["true"]

What am i doing wrong? How can I pass object to URL and then get the same object?

You shouldnt do that in Template. Have a look at the examples from README

and check subscription management with flowrouter

Collection is too little I publish it fully. Then queries occur on the client.

The question is "How to pass to query param object like {'maps.11': true} and then get the same object.

well, it is not suppose to take object as argument.
You can try serialize it and pass that as argument.
Than deserialize it to use in find.

1 Like

I think if you want to nest parameters in that way you should encode/decode it in someway, perhaps with jQuery.param()

Just tried shock's advice and it works fine for now. Thanks.

See my entries from this post:

FlowRouter.route('/about/', {
  yourObject: { maps: true },
  yourFunc: function() { return { maps: true } },
  action: function(params) {
    BlazeLayout.render('appLayout', {app_data: { title: 'Hello World'} });
  }
});

and access in Template via:

FlowRouter.current().route.options.myObject / myFunc()

But you also just send the param value through the route if that is the only param.