How to query on the server only on the first load in Nextjs App Router? #73646
Unanswered
longprao
asked this question in
App Router
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using react-query but open to any other pattern. I have asked in the react-query repository but did not have a good answer.
Expected:
Previously in Pages Router, it was achieved using
getInitialProps, like so:In App Router:
With this setup it will hit the server and wait for data fetching all the time (unless visited, or prefetched), which is a slow navigation experience. How to detect whether it's the first load?
In general, we have been maintaining many react apps with Pages Router. We are exploring moving to App Router, but only if it could guarantee the same performance and user experience. Especially we are using
getInitialPropsa lot, and looking to have the same functionality (unless it is wrong?).Beta Was this translation helpful? Give feedback.
All reactions