How to manually `revalidatePath('/example')` on REST?
Answered
Turkish Angora posted this in #help-forum
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
My API doesn't reload the page if I use
I also tried
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
You can simply call router.refresh() after calling the API
4 Replies
@Turkish Angora 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`:
ts
const { data: json, error } = await rpc.api.example.get({
fetch: {
cache: "no-store"
}
})
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
You can simply call router.refresh() after calling the API
Answer
@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
Turkish AngoraOP
you mean this router, right?:
import { useRouter } from 'next/navigation'Yes
@joulev Yes
Turkish AngoraOP
That's what I was looking for. Thanks! 
