yellow
yellow

Reputation: 702

vue-router: skip page when using browser back button

I have a "Home" page and a "Success" page in my application.

The Success page has a button that, when clicked, goes to a URL like https://google.com, via window.location.href='https://google.com'.

I can start on the Home page, use vue-router to push to the Success page, and then click the button to go to the URL. However, when I press the browser's back button, I'd like it to go back to the Home page instead of the Success page.

How can I do this?

Upvotes: 1

Views: 1741

Answers (1)

thanksd
thanksd

Reputation: 55634

Assuming your javascript is within a Vue instance, you can add a call to $router.replace right before setting window.location.href.

It would look something like this:

methods: {
  onLinkClick() {
    this.$router.replace({ name: 'home' }); // or whatever your home page name is
    window.location.href='https://google.com';
  }
}

Here's the documentation for vue-router programmatic navigation.

Upvotes: 2

Related Questions