How to invalidate Route cache for a specific path on the client?
Unanswered
Chinese softshell turtle posted this in #help-forum
Chinese softshell turtleOP
I have a button that will POST a resource via API (POST /diagrams). If a user then navigates to the resource page (/diagrams), and the navigation is not the initial one, the data is stale. I've read this article https://nextjs.org/docs/app/building-your-application/caching, and in the Route cache section (I assume this is this one, because no API request is made upon navigation) it tells that you can either invalidate the route in the server actions (I'm not using them), or only the current route with router.refresh. However, I want to invalidate the specific /diagrams page after clicking the button. How do I do that? The page itself is dynamic (it uses cookies)
1 Reply
For now, there’s no other way to revalidate router cache. My current workaround is to add a search parameter to the url, or call
router.refresh in a useEffect