My app is using React, but I’m not sure that’s relevant in this case.
What I’m trying to do is use a Mongo collection that stores slugs associated with names of React components. Flow Router should be able to access this collection. The problem is, I’m not clear on where to put my Meteor.subscribe so that this code below will work properly.
FlowRouter.route('/:slug', {
action(params) {
let tmpl = Templates.findOne({slug: params.slug});
if (tmpl) {
ReactLayout.render(eval(tmpl.component));
} else {
ReactLayout.render(NotFound);
}
}
});
Flow Router is built to route, not to handle anything subscription-related. For Blaze-users, this means handling subscriptions in templates. I wouldn’t know how to handle it for React.
This problem would also exist in Blaze. Before any templates have even been rendered, I need to pull data from a collection and use that information when deciding how to route a user.
Obviously when FlowRouter.go is executed, we lose the subscription since it’s inside this component only. I really need some way to have the router be able to access the Templates collection directly.
I don’t really understand the Fast Render approach. It supposedly relies on the subscriptions property in Flow Router, which is being deprecated in 3.0. Is there some other way?
And then Container would subscribe to the templates, fetch the component name to render, and then maybe use React.cloneElement or React.createElement to render it.