Shallow routing?
dminkovsky opened this issue · 4 comments
What's the best way to do what Next.js calls "shallow routing"?
Shallow routing allows you to change the URL without running data fetching methods again, that includes getServerSideProps, getStaticProps, and getInitialProps.
You'll receive the updated pathname and the query via the router object (added by useRouter or withRouter), without losing state.
Are you using Found Relay?
Nope!
We don't necessarily have an out-of-the-box way to do this. You can sort of implement this yourself, though. Two options:
- If you're not changing the URL involved, in your
getData
calls, just check your cache to see if the data you need are already present; if so, just serve those data instead of refetching (this is what Found Relay does by default, which is why I asked) - When pushing/replacing to a new location, add e.g.
shallow: true
to thestate
of the location, then use this in yourgetData
and other methods to skip data fetching if that state is set and if the current transition is aPUSH
orREPLACE
Thanks just making sure.
When pushing/replacing to a new location, add e.g. shallow: true to the state of the location, then use this in your getData and other methods to skip data fetching if that state is set and if the current transition is a PUSH or REPLACE
is what I was going to do, unless I was missing an existing way.
Cheers.