While Googling around for something, I landed on a page that had some interesting tidbits of information. I was interested in reading other articles and saw what looked like a plain back button that looked like it would navigate me to a list of other articles I could read on the site. To my surprise when I clicked on the button, it actually took me back to my Google search result.
history provides in
history.go() is a browser’s history. The
.go() method allows you to navigate to a specific point in the browser’s history. So in the scenario where the assumption is that the user was browsing around a website, it is probably safe to assume by using a
history.go(-1) to navigate to the immediate previous page would result in the intended action.
But as discovered above, it is quite possible to land on a page from an external site other than the one you’re currently on. Thus using the
history API will result in a unpleasant experience. The safer and better solution is to just use a relative or absolute path in relation to the site the back button is on. That way no matter the point of entry, the intended action of navigating to another page on the same website is accomplished.