Hey guys,
I’ve just moved for my new project from Iron:Router to FlowRouter and now having some trouble with one of my routes. I’ve defined a “catch all” route, because for some SEO reason I want to have the title of a question directly behind the url.
This is my defined route:
FlowRouter.route('/:id/', {
action: function(params, queryParams) {
BlazeLayout.render('layout', { site:"question" });
}
});
So f.e. I open a question by “myapp.com/how-late-is-it”. There is a button where I can move to the next question, so the next route will be f.e. “myapp.com/whats-your-name”. But here nothings happens, the template isn’t destroyed and there is no onRendered()
called again. I know that there are some differences how Iron:Router and FlowRouter handle things, but how can I tell FlowRouter that the route has changed? When the user clicks “next question” this function is called:
FlowRouter.go("/" + newQuestion + "/");
The url in the browser bar changes but the template and title remain the same.
If I understood the docs right, I’ve to call FlowRouter.reload();
. But this is also not working.
FlowRouter.go("/" + newQuestion + "/");
FlowRouter.reload();
//Edit: Answered here. I’ve added the subscription into an autorun, works now fine. @sashko Is this issue a topic in the current Meteor guide?
Template.question.viewmodel({
subReady: false,
dbObject: {},
flowId() {
return FlowRouter.getParam("id");
},
answers() {
return Answers.find({questionId: this.flowId()}, {sort: {votesUp: -1, createdAt: 1}});
},
onRendered() {
//Normally everything in the autorun function is here but FlowRouter doesn't do a rerender if you visit the same route with other parameters.
},
autorun: [
function () {
this.templateInstance.subscribe("question", this.flowId(), () => {
DocHead.removeDocHeadAddedTags();
this.subReady(true);
this.dbObject(Questions.findOne({id: this.flowId()}));
DocHead.setTitle(this.dbObject().title + " - myapp");
DocHead.addMeta({name: 'description', content: this.dbObject().desc.substr(0, 80)});
});
}
]
});
I really get that feeling that we do easy things more complex only to get “a little bit” better performance…