Next.js Discord

Discord Forum

How to manually `revalidatePath('/example')` on REST?

Answered
Turkish Angora posted this in #help-forum
Open in Discord
Turkish AngoraOP
Hi,

In App directory, without using Server Actions.

In client components, when I make a mutation (fetch request to api). How do I make the Page component reload the data? Currently it works with location.reload(). But is there Nextjs specific way?

My API doesn't reload the page if I use revalidatePath('/example') in /api/[[...slugs]]/route.ts which mount a WinterCG compat router Elysia (smth similar to Express).

I also tried no-store:
  const { data: json, error } = await rpc.api.example.get({
    fetch: {
      cache: "no-store"
    }
  })
Answered by joulev
Calling the API doesn’t do anything to the page. Only server actions, which tightly couple with the client side router, can do that.

You can simply call router.refresh() after calling the API
View full answer

4 Replies