Search code examples
meteoriron-router

How to call method in route?


I have two forms of search

POST /search
GET  /search?q=q

For POST, I can just use Meteor.call in client.

'submit form': function() {
    Meteor.call('search', data......
}

For GET, How can I call Meteor.call in router?

Router.route('/search', {
  template: 'ItemList',
  data: function() {
  return Meteor.call('search', this.params.query); // ???
}

and about the search method, it will not only search database but also search file system.

I don't know how to do the second GET search.


Solution

  • I would suggest not doing the calls in your router. The router is responsible for directing the flow of actions and it would make it more complex if it was also managing all of the data and external resource tracking.

    In the template level, you could easily detect the routers params (Router.current()) or have them passed directly from the router in the data section.

    Then on rendered you could have the template hit your call function. And then make it reactive with some dependency tracking