How does vue prevent $router.back () from jumping out of the current site?

assume that the browser currently opens Baidu home page , and then enter a page of the site in the address bar, which contains a return button with the code as follows:

methods: {
    goBack(){
        this.$router.back()
    }
}

when you click the back button (maybe there is only one back button on the page), the browser will navigate to the Baidu home page , how to prevent this problem?

Jul.15,2021

can judge document.referrer , not your master site directly skip to the home page.


think of a way to store the source address in the route interceptor. If the source address is not a route from the current site, set the source to homepage . When $router.back () , $router.replace (currPath) is fine

.
Menu