ssrwpo / ssr

SSR - Router with SSR for Node & Meteor
https://ssrwpo.github.io/ssr/
MIT License
93 stars 16 forks source link

Q: prepareStore is not called at all #68

Closed luski closed 7 years ago

luski commented 7 years ago

I have a question. I created an almost empty project with createRouter on server-side and client-side. Everything works, the main page is rendered correctly on the client and server side. Now I wanted to display some data from the mongodb. So AFAIK, to do it on the server side I should implement the prepareStore method, right? So I added to my main component:

AppRouter.ssr = {
  prepareStore: () => {
    console.log('prepareStore called');
    return false;
  }
}

just to test if the prepareStore will be called. And it's not - I can't see any console log on the server. What should I do to make the prepareStore be called?

cbilotta commented 7 years ago

Hello,

prepareStore only works with the develop branch, not in the package currently published to atmosphere!

luski commented 7 years ago

Oh I see, thanks. Is there any other way to render data from the db using the currently published package?

cbilotta commented 7 years ago

Yes, you have the global collection method. The problem is that you have to load the contents of the entire collection upfront. The router started being made for a very specific purpose so it was the only way to load data when we started. There are example in the demo of the master branch. Or, you can simply clone the develop branch in your packages folder so you can use the prepareStore methods. But, it is indeed a work in progess, so you might encounter a few bugs. I use it, and it's quite fine. But be ready to struggle a little if you decide to use it.

luski commented 7 years ago

Thanks for explanation :+1: