Next.js Discord

Discord Forum

How to refresh target page after router.push

Answered
Lionhead posted this in #help-forum
Open in Discord
LionheadOP
We have two pages: list and create. List is force-dynamic and revalidate 0. when successfully (client side) creating a new item in the create page we invoke a router.push(..) to redirect the user to the list page. However, the content of the list page is not updated.

We use latest next.js and prisma. Any ideas?
Answered by Clown
You'll have to do a router.refresh() in addition to that router.push() for it to work.

Also i think just using server actions would work too but im not too well-versed in those.
View full answer

7 Replies

You'll have to do a router.refresh() in addition to that router.push() for it to work.

Also i think just using server actions would work too but im not too well-versed in those.
Answer
LionheadOP
Thx. I'll give it a try.
@Clown didn't work. Went to the extreme:
      router.refresh();
      router.prefetch(routeSegments.dashboard.marketingUpdates);
      router.push(routeSegments.dashboard.marketingUpdates)
      router.refresh();


now trying server actions
You shouldn't need to prefetch.

I'm not sure if this is the best way but i basically do push() then refresh().
Also are you getting that cache hit/miss message in console when you open the list page?
LionheadOP
removing the prefetch worked for me. Thank you
@Lionhead removing the prefetch worked for me. Thank you
:sunglasses_1: mark the answer pls