Next.js Discord

Discord Forum

why i had to do router.refresh() just after router.push(url) to avoid the page contents being cached

Unanswered
Western Meadowlark posted this in #help-forum
Open in Discord
Western MeadowlarkOP
I'll try to explain without code . Im also using next 13.5

So I have page 1 and page 2. The first thing I get to is page 1. I have a button there which is a client component it does a router.push(page2 url) . When I click on that btn I go to page 2 and the db calls happen in the server part of page 2 and populate the page. Page 2 has buttons for doing network calls (CRUD stuff).
Page 2 has a button to go back to page 1 that does router.push(page 1).

My problem is sometimes when I go back to page 1 the new contents are not shown in page 1. And even after that I click again the button on page1 to go to page 2 it serves an old page 2 which also has some old data
When I keep clicking these 2 page navigation buttons back and forth there comes a situation that it will invalidate old and send the updated contents. But when and how it is decided I have no clue

I did a router.refresh() right after the router.push() then it seems like to load new data for the page you are going.

btw page 1 is like /products/:id and page2 is like /products/:id/edit

Is this the proper way of doing this. Looks a bit hacky since I couldnt find it anywhere in the cache opting pages in next docs

1 Reply