What is the best way to force a hard reload in Nextjs?
My current use case:
- The web application asks the user for the geolocation
- If the user denies the geolocation I want to show him an error message, that the geolocation is needed
To improve the user experience I would like to give the user the option to do a page reload, so that the user will be asked again for his geolocation. It seems that a hard reload is required for this.
If there are better ways to ask again for the user geolocation, please don't hesitate to tell me about it.
If a hard reload is the way to go, those are the steps I tried and failed:
with useRouter
const router = useRouter()
router.reload()
This does not perform a hard reload and thus doesn't ask the user again for the geolocation.
with window.location
window.location.reload();
Same expected behaviour than with useRouter.
Add cache-control
<Head>
<meta httpEquiv="Cache-Control" content="no-store, max-age=0" />
</Head>
This does not perform a hard reload and thus doesn't ask the user again for the geolocation.