next-react-router
next-react-router copied to clipboard
Async data prefetch for pages
I wonder if there is any way to prefetch data during SSR like NextJS provides convenient SomePage.getInitialProps
functionality following the approach?
Btw, Great job! I’ve been dreaming about NextJS+RR for couple months.
Hi! I expect any NextJS feature not relying on the native routing system (like static pages and partial local dev builds) to work as expected.
Got it. At the same time getInitialProps
being triggered in process of NextJS routing lifecycle, so it's not expected to be working. Right?
For example, i've added:
function About() {
return <h2>About</h2>;
}
About.getInitialProps = () => {
console.log('About says: Gimme some data, please.');
};
to example https://github.com/toomuchdesign/next-react-router/issues/1 and About.getInitialProps
not being called.
Do you see any chance to bring it back to fulfill SSR with async data?
I'm sure there is room for improvement but, given the feedback I got from nextJS maintainers, I won't spend any time on this subject. I stay open to PR's, btw.
Just out of curiosity, what was some of the feedback you got from NextJS maintainers?
Hello guys, I was in the same situation and found a possible alternative. In case you can use apollo
and fetch your data with Graphql, they have a very good solution in place where they query getDataFromTree
and look for all the queries
inside the components, resolve them and then return the rendered components with all the data inside! This method is hooking inside the original getInitialProps
, you can find the code here --> https://github.com/zeit/next.js/blob/canary/examples/with-apollo/lib/apollo.js#L106
Besides, you are still not being able to use getInitialProps
directly, you can query data on the server-side 😄
The full example is here --> https://github.com/zeit/next.js/tree/canary/examples/with-apollo Hope it helps other 👍