0

I've seen this thread on how to append/modify query parameters without duplicating, but I can't make it work.

I have a page in my Meteor application that lists items and allows filtering. I would like the filtering to be URL-based, so every change to a filter should reflect in the URL. I use iron-router to then update the subscription accordingly.

For some reason, I can't modify the querystring though. This code doesn't trigger any action if called from a Template.templateName.events(...):

# valuePairs = ["foo=bar", "bar=foo"]    
newUrl = Router.current().route.path {}, { query: valuePairs.join('&') }
Router.go newUrl

But if I call Router.go(newUrl) from the commandline, the expected result happens, i.e. the URL updates.

Is there another, preferred method to modify the query?

If not, how can I make above code work?

UPDATE - I just found that after running the event, if I go back in my browser history I can see the correct URL. It looks like something (?) triggers another page load to go back to original page.

Community
  • 1
  • 1
neo post modern
  • 2,262
  • 18
  • 30

1 Answers1

0

Just based on

if I go back in my browser history I can see the correct URL

Do you suppress the actual link event? An <a href='#'> would flip flop you right back.

Template.tempyTheTemplate.events({
    'click awesomeButton': function() {
        // URL stuff
        Router.go(magicURL);
        return false;  // <-- suppresses the event
    }
});
Marius
  • 893
  • 1
  • 8
  • 12
  • Oh, I had completely forgotten about this question. The same you proposed here was resolved on [GitHub](https://github.com/iron-meteor/iron-router/issues/900#issuecomment-59673360) when I was still having the issue. Thank you anyways. And I (personally) find `event.preventDefault()` more readable/obvious, but that's just preferences. – neo post modern Jul 09 '15 at 14:51