tmeasday / meteor-router

MIT License
366 stars 76 forks source link

Missing data when directly go to a route? #87

Open derekchiang opened 11 years ago

derekchiang commented 11 years ago

I'm experiencing a very strange issue and I wonder if that's caused by meteor-router. So apparently if I navigate to a page from the index by calling Meteor.Router.to, everything is good. But if I just go to the URL directly, all collections are missing (SomeCollection.find({}) returns an empty collection). Does anyone have any clue why?

I'm using Meteor 0.6.3 with the latest meteor-router.

tmeasday commented 11 years ago

Meteor has not yet loaded the data from the server.

Eventually the router will help you with this, but for now just ensure you don't throw errors when data is loading.

El 29/05/2013, a las 4:44 PM, "Derek Chiang (Enchi Jiang)" notifications@github.com escribió:

I'm experiencing a very strange issue and I wonder if that's caused by meteor-router. So apparently if I navigate to a page from the index by calling Meteor.Router.to, everything is good. But if I just go to the URL directly, all collections are missing (SomeCollection.find({}) returns an empty collection). Does anyone have any clue why?

I'm using Meteor 0.6.3 with the latest meteor-router.

— Reply to this email directly or view it on GitHub.

derekchiang commented 11 years ago

Thanks I see... what's the best way to get around this? Would you suggest me to use setTimeout? But if the user is navigating from other pages to that route, in which case the data is loaded, then there is no need to make him wait. How do I detect whether a user is going directly to that route? Maybe by setting a session variable on other pages and check for the presence of the variable on that route? Any thoughts would be appreciated.

tmeasday commented 11 years ago

Hi Derek.

There are 3 levels of approaches.

  1. Just display nothing until the data has loaded. It's easy to just use something like {{#if post}} to render nothing while you wait for the post to load. When the data arrives it'll reactively re-render as long as you haven't thrown an error.
  2. Use something like https://github.com/oortcloud/unofficial-meteor-faq#how-do-i-know-when-my-subscription-is-ready-and-not-still-loading to wait until the relevant subscription has loaded and show a loading page in the meantime.
  3. In the near future the router will better support you in this (extremely common) use case.
derekchiang commented 11 years ago

Good idea! Thanks a lot for help.