Vue2 navigate to external url with location.href

前端 未结 3 2006
盖世英雄少女心
盖世英雄少女心 2021-02-12 16:03

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.mytarge

3条回答
  •  一整个雨季
    2021-02-12 16:29

    No need to use navigation guards in this case, cleaner to use dynamic redirect right there in route config

    routes:[
      {
        path: '/redirect-example',
        redirect: (to: Route) => {
          window.location.href = 'http://example.com'
          return '/redirecting' // not important since redirecting
        }
      }
    ]
    

提交回复
热议问题