Use <Link> with next/navigation, but disable cache on specific Page
Unanswered
! VINKE posted this in #help-forum
! VINKEOP
Hello, I am using <Link> from next/navigation in my project, but I want to know if it is possible to disable cache on a specific page.
Every time the user navigates to that specific page/route, SSR reloading should be mandatory.
I tried using export const revalidate = 0; but it doesn't work on my project (maybe I'm using something else that's blocking it, or I'm not using it the right way 😂)
I try to see in gtp discord part with out result : https://discord.com/channels/752553802359505017/1304219731993301194
Every time the user navigates to that specific page/route, SSR reloading should be mandatory.
I tried using export const revalidate = 0; but it doesn't work on my project (maybe I'm using something else that's blocking it, or I'm not using it the right way 😂)
I try to see in gtp discord part with out result : https://discord.com/channels/752553802359505017/1304219731993301194
9 Replies
@! VINKE Hello, I am using <Link> from next/navigation in my project, but I want to know if it is possible to disable cache on a specific page.
Every time the user navigates to that specific page/route, SSR reloading should be mandatory.
I tried using export const revalidate = 0; but it doesn't work on my project (maybe I'm using something else that's blocking it, or I'm not using it the right way 😂)
I try to see in gtp discord part with out result : https://discord.com/channels/752553802359505017/1304219731993301194
so essentially you want to disable the [router cache](https://nextjs.org/docs/app/building-your-application/caching#client-side-router-cache) for one specific page? afaik it is not possible, you have to either configure it app-wide [using
staleTimes](https://nextjs.org/docs/app/api-reference/next-config-js/staleTimes) or use <a> instead of <Link>@joulev so essentially you want to disable the [router cache](<https://nextjs.org/docs/app/building-your-application/caching#client-side-router-cache>) for one specific page? afaik it is not possible, you have to either configure it app-wide [using `staleTimes`](<https://nextjs.org/docs/app/api-reference/next-config-js/staleTimes>) or use `<a>` instead of `<Link>`
! VINKEOP
yes but the problem is if i use <a> instead <Link>, everytime i open this specific page, the others cached page get refresh, and the navigation smooth is lost
not much can be done though. nextjs does not allow you to opt part of the app out of the router cache while maintaining the cache in other parts
@joulev not much can be done though. nextjs does not allow you to opt part of the app out of the router cache while maintaining the cache in other parts
! VINKEOP
yeah make sense, and another question, if i use router.refresh() from next/navigation, that mean i refresh everything ?
yes
@joulev yes
! VINKEOP
ok so if i create an inventory app with <Link> and want to use cache for better experience
When the user adds items to their inventory, go to another page and come back, how can I ensure that the item is always displayed in their inventory knowing that the data is cached?
When the user adds items to their inventory, go to another page and come back, how can I ensure that the item is always displayed in their inventory knowing that the data is cached?
@! VINKE ok so if i create an inventory app with <Link> and want to use cache for better experience
When the user adds items to their inventory, go to another page and come back, how can I ensure that the item is always displayed in their inventory knowing that the data is cached?
adds items to their inventoryyou should use a server action for this. inside the action, simply
revalidatePath/revalidateTag to tell nextjs that the data has changed