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?
天蓬老师2017-06-26 10:56:01
You can think of the router as a stack of access records. router.replace()
replaces the top of the stack, and router.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 use router.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 use replace
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.
大家讲道理2017-06-26 10:56:01
If there is no history, the browser will not be able to find the previous page when it goes back.