59. create a browser history
Share
medium - accepted / - tried
I believe you are very familiar about your browser you are currently visiting https://bigfrontend.dev with.
The common actions relating to history are:
new BrowserHistory()
- when you open a new tab, it is set with an empty historygoBack()
- go to last entry, notice the entries are kept so thatforward()
could get us backforward()
- go to next visited entryvisit()
- when you enter a new address or click a link, this adds a new entry but truncate the entries which we couldforward()
to.
Say we start a new tab, this is the empty history.
[ ]
Then visit url A, B, C in turn.
[ A, B, C] ↑
We are currently at C, we could goBack()
to B, then to A
[ A, B, C] ↑
forward()
get us to B
[ A, B, C] ↑
Now if we visit a new url D, since we are currently at B, C is truncated.
[ A, B, D] ↑
You are asked to implement a BrowserHistory
class to mimic the behavior.