Nextjs finally added the feature everyone requested: staleTimes: https://nextjs.org/docs/app/api-reference/next-config-js/staleTimes .
but this doesn’t work for router.back() as stated in the docs.
Following problem:
If you used a Link in the past even though it was dynamic the values got cache 30 sec.
In the new experimental feature you a specify this time yourself. For example to 0 (to disable the cache)
This all works pretty good and is awesome. But there is still one problem.
If you have two pages
- list of data
- detail page
On the first page you have links which point to the detail pages (for example list/:id)
On the second page you have a back button that executes router.back() that caches the previous page
Unfortunately staletime doesn’t work for router.back()
You could also use a link as a back button ( that would work and you always see up to date data.
But if you have set query params on page 1 through a filter for example you have no idea where to link back to.
In previous version you could do
router.back()
router.refresh()
on page 2. to get updated data on page 1, but this no longer works.
What would be a workaround
Help appreciated