Flowrouter is super smooth until I remove autopublish. Whenever I remove it the reactive subscribed templates start flickering whenever the url changes.
Is there a way to tell flowRouter to wait until subscriptions are ready before starting the next route?
Just curious, what’s the purpose of the asterisk after :uniquePageUrl ? I haven’t seen that before with FR, and I’m not sure if it’s a typo or you know something I may not. Can’t find anything in FR docs.
It makes sense that you would experience a slight delay as you are re-running an autorun to load the updated subscription with each route change. The data is already available client-side when you are using autopublish, so no delay occurs.
You can update your onCreated callback to something like this to display a loading template or similar while you are fetching data (assuming you are using ReactiveVar, if not you could use Session too):
Template.pageTmpl.onCreated( function() {
var self = this;
self.ready = new ReactiveVar(false);
self.autorun(function(comp) {
var uniquePageUrl = FlowRouter.getParam('uniquePageUrl') || "/";
self.subscribe('singlePage', uniquePageUrl, function () {
self.ready.set(true);
comp.stop()
});
});
});
You can pass a callback to template.subscribe() that will run once the subscription is fully loaded.
Thanks Adamsidiali, I’ll try that out!
With regards to '/uniquePageUrl*', I was looking for a solution to enable a user to define a route themselves for a CMS.
While researching I found out that FlowRouter routes are based on path-to-regexp which is capable of something called zero-or-more. I’m not sure if this is the best solution but its working ok for me.