Next.js Discord

Discord Forum

router.refresh() before or after router.push()

Unanswered
Polar bear posted this in #help-forum
Open in Discord
Polar bearOP
After awaiting a mutation response from either a POST (create an item) or DELETE (delete an item) route hander, is it best practice to call useRouter's router.refresh() before or after router.push()?

In Next 14.0.1 it seemed to not make a difference which order these methods were called and produced the same results (navigated to the new route and showed the up to date data) however, in Next 14.1.4 it seems that if you call router.refresh() before router.push(), the route cache is not invalidated and the pre-mutation data in shown.

Now that I have updated to Next 14.1.4, the desired outcome is only achieved when router.refresh() is called after router.push(). Can anyone please give me some insight to why I am observing this behavior?

Thanks in advance!

0 Replies