Disable router cache completely
Answered
Belgian Hare posted this in #help-forum
Belgian HareOP
Hi, is it possible to disable caching when switching routes? like if i made a change on
I'd like to turn off cache while switching routes completely, our site isnt static.
abc page and switch to previous page xyz then switch back to abc again, abc still has old data even after revalidation.I'd like to turn off cache while switching routes completely, our site isnt static.
Answered by joulev
use proper revalidation methods (
revalidatePath/revalidateTag/router.refresh) instead25 Replies
@Belgian Hare Hi, is it possible to disable caching when switching routes? like if i made a change on `abc` page and switch to previous page `xyz` then switch back to `abc` again, abc still has old data even after revalidation.
I'd like to turn off cache while switching routes completely, our site isnt static.
Disable router cache completelyno, it's impossible.
use proper revalidation methods (
revalidatePath/revalidateTag/router.refresh) insteadAnswer
@joulev > Disable router cache completely
no, it's impossible.
Belgian HareOP
oh boi :/
@joulev use proper revalidation methods (`revalidatePath`/`revalidateTag`/`router.refresh`) instead
Belgian HareOP
those are all manual
ive to do it for whole site
then use client-side rendering
use tanstack query and route handlers
Belgian HareOP
ugh that'd be too much, whole codebase's using server stuff 

you are simply using cache the wrong way. there is no way to disable the router cache.
Belgian HareOP
shouldnt force-dynamic work?
force-dynamic doesn't change anything if the route is already dynamic
@joulev you are simply using cache the wrong way. there is no way to disable the router cache.
Belgian HareOP
i just want new data to be displayed when switching routes, our tester wont understand this
could use date in the href but thats more of a workaround 

tell them that's a feature to reduce load on the server
not a bug
you technically can just patch nextjs to remove the router cache. i wouldn't recommend that though unless you know what you are doing
Belgian HareOP
he wont get it, old data shown on previously visited pages is annoying
or is it possible to make Link not use cache?
no as i said, you are just wishing for the impossible. if you don't patch nextjs, you cannot remove the router cache and that's a hard fact you have to accept
@joulev no as i said, you are just wishing for the impossible. if you don't patch nextjs, you cannot remove the router cache and that's a hard fact you have to accept
Belgian HareOP
so only thing i could do is revalidate page in useeffect with empty deps
and that works
@joulev use proper revalidation methods (`revalidatePath`/`revalidateTag`/`router.refresh`) instead
use these functions, how to do that depends on your code
but use those functions to remove the cache
working all good 
