How to always reload a dynamic page
Unanswered
Australian Freshwater Crocodile posted this in #help-forum
Australian Freshwater CrocodileOP
I just can't figure out how this can be reloaded. I've got a dynamic path
/search/[id]. When I'm in one and use server actions to update things in database (Neon serverless) the response is saved to the database. If I navigate to another [id] and come back, the update isn't visible, but I see it when I refresh the page. How not to require the page refresh?4 Replies
I think you can use
I heard Next 15 doesn't cache by default, not sure tho. haven't used it yet.
revalidatePath ? https://nextjs.org/docs/app/api-reference/functions/revalidatePath#server-actionI heard Next 15 doesn't cache by default, not sure tho. haven't used it yet.
Australian Freshwater CrocodileOP
I've tried quite extensively, I'm currently running this after the saving to db (haku is search mentioned):
revalidatePath('/', 'layout');
revalidatePath('/', 'page');
revalidatePath('/haku', 'layout');
revalidatePath('/haku', 'page');
revalidatePath('/haku/[id]', 'page');
revalidatePath('/haku/[id]', 'layout');
revalidatePath(`/haku/${chatId}`, 'page');
revalidatePath(`/haku/${chatId}`, 'layout');But it does nothing
Australian Freshwater CrocodileOP
I added this to a client component that uses the data, it helped:
const router = useRouter();
useEffect(() => {
router.refresh();
}, [router, id]);`