Next.js Discord

Discord Forum

Ordering router.push and router.refresh

Unanswered
Black Caiman posted this in #help-forum
Open in Discord
Black CaimanOP
I have quite a few situations where I often want to refresh the client-side router data, and redirect the user at the same time.

For example, I have a "delete post" button that makes an API request to delete a post. I then redirect the user to "/posts". When I do this:
// Theoretically resetting client-side cache
router.refresh();
router.push('/posts');

I expect that the "/posts" page will be refetched as I've cleared the client-side router. That does not appear to be true.

When I reverse these, it works (the user is redirected and the page is refetched with fresh data):
router.push('/posts');
router.refresh();

That seems counter-intuitive to me. Why does the first one not work?

0 Replies