1. history principle

The visited addresses are stored on a stack (LIFO-last in first out)

2. history.go()

/home ==> /home/qa ===> /home/video

  • history.go(-1) // return to previous page,
  • history.go(1) // go forward one page

3. history.replace() & history.push()

Location Replace: The link of the page is set to the new one, but the user can’t go between the replaced.
In short, history.replace() will jump pages, but instead of adding a record, it will replace the current record

History Push: The user can go forward and backward in the browser and the url will change. It works like a programmatic link with no affect on current url.
In short, history.push() jumps pages and adds a record to the page stack

3.1 Scenario

e.g.
A user is logged in, in a social app. When the user clicks follow, the token expires and the user jumps to /login.
After login, the user goes back to the following page. After clicking follow, the user clicks the back button. If the /login page was jumped by replace(), it goes back to the previous page of follow; if it was push(), it goes back to /login.


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

Catalogue