【问题标题】:How to remove the hashtag in the url with vue router?如何使用 vue 路由器删除 url 中的主题标签?
【发布时间】:2022-01-09 01:01:24
【问题描述】:

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

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

这就是为什么我想问一下是否可以在vue项目已经生成时使用切换到历史模式?

这是我的网址:http://localhost:8081/#/

【问题讨论】:

    标签: vue.js url localhost vue-router


    【解决方案1】:

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

    对于路由器 v3:

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

    对于路由器 v4:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-24
      • 2018-05-16
      • 2019-08-15
      • 2014-05-13
      • 2020-12-30
      • 1970-01-01
      • 2019-11-04
      • 2020-03-27
      相关资源
      最近更新 更多