Created
June 30, 2014 18:00
-
-
Save OnlyInAmerica/409a50264025df634126 to your computer and use it in GitHub Desktop.
How to redirect with Iron-Router without breaking Browser's back function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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