I expected the data fetching to happen server-side on first load and be cached
Data is fetched by the client (I see the network request) on first load
const activeItem = router.pathname to set active item on menuIf I remove that line everything is ok and I don't see any client-side fetching.
Thank you,
Matteo
@ads1018
If you're following the with-apollo example you'll need to include router in the context of getDataFromTree otherwise withRouter won't find the router in the context when rendering on the server.
I got it working using:
const url = { query: ctx.query, pathname: ctx.pathname, asPath: ctx.asPath }
try {
await getDataFromTree(
<ApolloProvider client={apollo}>
<BaseComponent url={url} {...initialProps} />
</ApolloProvider>,
{ router: url },
)
} catch (error) {
console.warn(error)
}
Notice how { router: url } is passed as the second argument to getDataFromTree
Thank you! It works! :)
@simenbrekken that's neat. I didn't know getDataFromTree accepted a second argument.
This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.
Most helpful comment
If you're following the with-apollo example you'll need to include router in the context of
getDataFromTreeotherwisewithRouterwon't find the router in the context when rendering on the server.I got it working using:
Notice how
{ router: url }is passed as the second argument togetDataFromTree