[Vuejs]-Vue router refreshing page instead of navigating to it. What is the difference between these 2 code examples?

0👍

use router.push(url) instead of router.go(url)

when using vue router its a good practice to use router.push to navigate instead of location.href because the later may produce some unexpected behavior.

0👍

router.go is a method to be used when you want to move ‘x’ number of pages forward of backward in your browsing history.

router.push is to navigate to a page by adding a new item in the browser history. But it is meant for pages inside your application. Ex – going from ‘/about’ page to ‘/careers’ page on the same website. That is why we give the relative path or a page name to the push method.

From what I can see you are trying to redirect to a completely different page. In that case you should use window.open to open the page.

If it is a link to a checkout page then it might be better to open in a new tab using window.open(url, '_blank')

Leave a comment