In vue2.0, the corresponding router2.0 explains that router.replace is very similar to router.push. The only difference is that router.replace does not add new records to history, but replaces the current ones. history record.
So what are the differences between the two application scenarios?
You can think of the router as a stack of access records.
router.replace()
replaces the top of the stack, androuter.push()
adds a new record to the stack.Under normal circumstances, to manage forward and backward browsing records, you basically use
router.push()
, but there are also some special cases where you need to userouter.replace()
. For example, there is an authorization page. When a user follows a process and requires authorization at a certain step, he or she jumps directly to the authorization page. The authorization page submits an authorization request. After successful authorization, it jumps to the address of the next step in the process. Here, the page of the authorization request should usereplace
to replace its own access record to prevent the user from jumping to the next step and then pressing the back button to return to the authorization page, resulting in repeated authorization.If there is no history, the browser will not be able to find the previous page when it goes back.