4

Using the latest Meteor and Iron Routing, how do I simply "go back" to the previous route? I feel silly even asking, because it seems this would be a main feature of Iron Routing..

For instance, say I went to "/contacts" from "/posts" and then I wanted to "go back" with my app's back button (not the browser button, though this does what I'd like this functionality to do) to /contacts again because that was the last route I was on. Is there not a one-line command for this such as Router.back() that I could put in a global routes file whenever this is triggered?

This seems like it would be a very common question, yet I can't find anyone that has asked it yet.. If so, forgive me and please direct me with a link.

Alex Pan
  • 4,341
  • 8
  • 34
  • 45

2 Answers2

6

To go back in iron-router, just use:

history.go(-1)

or

history.back()

Both of these are supported by iron-router.

Alex Pan
  • 4,341
  • 8
  • 34
  • 45
1
FooController.events({
    'click [data-action=back]' : function () {
        history.back();
      }
});

Sorry, I was looking for something like the above code, which I put into [InsertGlobalControllerName]Controller.Events()

I wanted to make it a global event so a back button could work on all layouts. I figured it out, thanks for the help!