'How to delete (the previous entry) from the Vue-router history?

I would like to delete the previous history entry in Vue-Router, is that even possible?? The solution must work in Vue-Router 4.x, and ideally in 3.x as well.

The scenario that I'm implementing here is that a user does:

 pageA -> pageA:edit -> pageB

When hitting "back" at pageB, I want to go to pageA (regular, non-edit) instead.

I know that I could instead of a push to history of the page A:edit page, simply do a replace. However, it feels more natural that when hitting back in the A:edit page, you are returned to the regular non-edit page (there already is a check for changes in the beforeUpdate route guard, so that's covered).



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source