I tried to go to 'www.mytargeturl.org' using router.go, router.push, router.replace and window.location.href to redirect my vuejs app but i always get myVueapp.com/www.mytargeturl.org Here's my route:
routes:[ {path: '/', component: App, children:[ { path: 'detail', component: ItemDetail, props: true }, { path: 'search', component: Middle } ] }, { path: '/test', component: Test }, { path: '/a', redirect: 'www.mytargeturl.org' } // also tried this but didnt work
]
Suppose we have a /contact route in our vue app, when a user visits the /contact page we need to redirect them to an external url https://www.google.com/contact/ instead of the same domain redirect. To redirect to an external url in Vue, we can use the window. location. href property.
But what if you want to redirect programmatically, without using an anchor tag at all? If you're using Vue Router you'll push the new URL onto the router in order to do a redirect: this. $router. push('www.yoursite.com/blog') .
Vuex is a state management pattern + library for Vue. js applications. It serves as a centralized store for all the components in an application, with rules ensuring that the state can only be mutated in a predictable fashion.
Agreed with the people in other comments. Vue's philosophy is not to solve already solved problems. Same here. Just use an ordinary a
tag for the link whenever possible. If you need to go through the router though, use Navigation Guards:
{ path: '/redirect', beforeEnter(to, from, next) { // Put the full page URL including the protocol http(s) below window.location.replace("https://example.com") } }
Found the solution. By adding http in my target url, all is well! Like this window.location = 'http://mytargeturl.org"
This seems to be universal javascript truth not just vue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With