Next.js Discord

Discord Forum

revalidatepath on an api route

Answered
Satin Angora posted this in #help-forum
Open in Discord
Satin AngoraOP
I am having to use server actions because somehow when running revalidatePath('/this/route') seems to not invalidate the cache. Is this an issue or is it meant to work this way?
How are you guys revalidating the path of the route you have update when using route handlers and not server actions?
Answered by joulev
nothing wrong, don't worry. that's just the controversial router cache
View full answer

24 Replies

async function onClick() {
  await fetch(...);
  router.refresh();
}
but why not even do that, just use server actions + revalidate functions
Satin AngoraOP
I am now changing everything again to server actions
its because i am currently migrating a project and want to revalidate from the api
i see. yeah using server actions is the recommended way, but if you want to force-flush the router cache without server actions then router.refresh() is the only way
Satin AngoraOP
but i see now that i have to use a client side if i use router.refresh()
don't you already have to use client components? else how do you send the mutation requests?
Satin AngoraOP
btw, in next docs it appears as if revalidate path works on route handlers
yes it does work, but it doesn't flush the router cache. so you still get the same stale data, but if you refresh the page (browser refresh button) you will get fresh data
@joulev don't you already have to use client components? else how do you send the mutation requests?
Satin AngoraOP
yes, but in this case i am using tanstack table and its a button inside a column
so there is no way of having router inside that variable
well i have never used tanstack table so can't help here
Satin AngoraOP
thank you for your answer
but certainly you should have a way to use hooks there right?
yeah have fun coding!
@joulev yeah have fun coding!
Satin AngoraOP
its easier to write a server action for that one and handle it there
i just wanted to understand if i was doing something wrong in the api handler
nothing wrong, don't worry. that's just the controversial router cache
Answer
only server actions and router.refresh() can invalidate it
Satin AngoraOP
thank you. have a great day
how do i mark this as a solution?
Original message was deleted
follow this