kadirahq/fast-render

Question: How to use FastRender with a initial redirect?

thomasf1 opened this issue · 2 comments

Probaply a dumb question:

Based on the user, on the "/" route we redirect to another route. How can we utilize that with FastRender?

It doesn´t need to be a redirect, rendering the other route would be fine, too...

example code:

Router.route "/",
    fastRender: true
    action: ->
        If Meteor.user().type is "seller" then Router.go "sell"
        If Meteor.user().type is "buyer" then Router.go "buy"

Router.route "/sell",
    fastRender: true
    waitOn: -> #tons of data
    action: -> #render it

Thanks,
Thomas

You can put this into server side code:

Meteor.publish("currentUser", function() {
  if (Meteor.userId()) {
    return Meteor.users.find(Meteor.userId());
  } else {
    return null;
  }
});
Meteor.startup(function() {
  FastRender.onAllRoutes(function(path) {
    const fr = this;
    fr.subscribe('currentUser');
  });
});

cause I recently encounter that the fast render didn't publish the roles field in the server side run of waitOn

I think @gilbertwat's answer is correct. You may need to use FastRender.onAllRoutes API. Otherewise, you can do a server side redirect. Then, fast-render will work.