Skip to content

Instantly share code, notes, and snippets.

@OnlyInAmerica
Created June 30, 2014 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OnlyInAmerica/409a50264025df634126 to your computer and use it in GitHub Desktop.
Save OnlyInAmerica/409a50264025df634126 to your computer and use it in GitHub Desktop.
How to redirect with Iron-Router without breaking Browser's back function
// My Iron-Router map has these two routes
// I'd like to redirect all requests to /forum/:id
// onward to /forum/:id/:slug
// Using this.redirect(...) works but prevents the
// browser from navigating "back"
this.route('questionDetailWithSlug', {
template: 'questionDetail',
path: '/forum/:id/:slug',
action: function(){
Session.set('questionId', this.params.id);
this.render()
},
layoutTemplate: 'layout'
});
this.route('questionDetail', {
path: '/forum/:id',
action: function(){
Session.set('questionId', this.params.id);
var question = ForumQuestions.findOne(this.params.id);
console.log(question);
this.redirect("questionDetailWithSlug", {id: this.params.id, slug: question.slug})
},
layoutTemplate: 'layout'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment