【发布时间】:2019-10-27 06:17:57
【问题描述】:
每当我尝试使用简单的
<router-link to="https://google.com">
Google
</router-link>
它将链接呈现到http://localhost:8080/https:/google.com
router.js
export default new Router({
mode: 'history',
base: process.env.BASE_URL,
)}
我没有.env 文件。每当我创建.env 并添加BASE_URL=http://localhost:8080 时,它都会呈现http://localhost:8080/http:/localhost:8080/https:/google.com
有人遇到过这个问题吗?
更新 上面的示例反映了外部网站,但内部链接也会发生这种情况。示例:
<router-link avatar :to="{name: 'author', params: {id: author.id, name: author.name}}"> foo </router-link>
定义作者路线
{
path: '/author/:id/:name',
name: 'author',
component: Author
},
几天前一切正常,但我必须添加一些东西来改变这种行为。我到处寻找,但似乎找不到哪里出了问题。
【问题讨论】:
-
不是重复的。我更新了答案以反映它不是一个重复
-
@Charlie 您需要使用
author路由的路由定义更新问题。 -
@Charlie 浏览器中生成的 URL 最终会成为您的
author路由。是不是类似于http://localhost:8080/{name: 'author', params: {id: author.id, name: author.name}}? -
@ceejayoz 作者的路线是:localhost:8080/author/348/Aaron%20Sorkin%0A 在
router.js定义base: undefined解决了问题
标签: vue.js vue-router