【发布时间】:2022-01-09 01:01:24
【问题描述】:
我在网上看到,url中的hashtag是由于vue路由器中没有使用history造成的。
目前,我正在做一个大项目,重新开始并在终端中选择历史模式会浪费时间。
这就是为什么我想问一下是否可以在vue项目已经生成时使用切换到历史模式?
这是我的网址:http://localhost:8081/#/
【问题讨论】:
标签: vue.js url localhost vue-router
我在网上看到,url中的hashtag是由于vue路由器中没有使用history造成的。
目前,我正在做一个大项目,重新开始并在终端中选择历史模式会浪费时间。
这就是为什么我想问一下是否可以在vue项目已经生成时使用切换到历史模式?
这是我的网址:http://localhost:8081/#/
【问题讨论】:
标签: vue.js url localhost vue-router
Vue路由器的默认模式是hash-mode。您不需要再次安装整个应用程序,只需在您定义 vue 路由器的应用程序中将模式更新为历史模式,如下所示:
对于路由器 v3:
const router = new VueRouter({
mode: 'history'
})
对于路由器 v4:
const router = VueRouter.createRouter({
history: VueRouter.createWebHashHistory(),
})
【讨论】: