如何使用 vue 路由器删除 url 中的主题标签?

How to remove the hashtag in the url with vue router?

我在网上看到 url 中的 hashtag 是由于在 vue router 中没有使用 history 造成的。

目前,我正在做一个大项目,重新开始和终端中的 select 历史模式会浪费时间。

所以我想问问是否可以在vue项目已经生成的情况下切换到历史模式?

这是我的url:http://localhost:8081/#/

Vue 路由器的默认模式是散列模式。您不需要再次安装整个应用程序,只需在您定义 vue 路由器的应用程序中将模式更新为历史模式,如下所示:

对于路由器 v3:

const router = new VueRouter({
  mode: 'history'
})

对于路由器 v4:

const router = VueRouter.createRouter({
  history: VueRouter.createWebHashHistory(),
})

供参考: https://next.router.vuejs.org/guide/#javascript