What is the trade off between history push and replace?
I like to use .replace()
when i have a definitive action and i dont want the user to be able to come back to this page.
Example: i have a product detail page with a delete button to ultimately deletes the product. When i click the button i do router.replace
back to the list of all products so when the user uses the back button in the browser he is not able to go back to the details page so he cannot see or even click again the delete button as this product does not exist anymore.
router.replace acts like router.push, the only difference is that it navigates without pushing a new history entry, as its name suggests - it replaces the current entry.
I think you have the right idea.
I personally use .replace
when redirecting from an invalid url (or non relevant, i.e. redirect to "profile" page when a logged user goes to the "/login" url), so using the browser's "back" button works properly for the end user.