Vue2 使用 location.href 导航到外部 url

新手上路,请多包涵

我尝试使用 router.go、router.push、router.replace 和 window.location.href 转到“www.mytargeturl.org”来重定向我的 vuejs 应用程序,但我总是得到 myVueapp.com/www.mytargeturl.org 这是我的路线:

   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

]

原文由 codely 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 943
1 个回答

同意其他评论中的人。 Vue 的理念不是解决已经解决的问题。同样在这里。尽可能使用普通的 a 链接标签。如果您需要通过路由器,请使用 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")
    }
}

原文由 damienix 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏