如何从 url 中删除主题标签?

How to remove hashtag from the url?

import router from './router'

Vue.use(router)    

new Vue({
      el: '#app',
      router,
      template: '<App/>',
      components: { App }
    })

我的 main.js 和另一个名为 index.js 的文件中有这段代码,我有组件的所有路径。我想知道如何从 url 中删除散列。有文档吗??我正在使用 webpack

使用 mode = history 配置您的路由器

const router = new VueRouter({
  mode: 'history',
  routes: [...]
})

https://router.vuejs.org/en/essentials/history-mode.html

vue-router 的默认模式是散列模式 - 它使用 URL 散列来模拟一个完整的 URL 这样当 URL 时页面不会重新加载changes.To去掉hash,我们可以使用router的history模式。 复制自vue-routerdocument,我们必须配置服务器(apache,nginx或其他)以确保index.html可以匹配,否则会得到404。

在我的 Vue.Js 版本中,您必须为新路由器添加 mode: 'history' 行。 Vue.use(路由器)

export default new Router({
    mode: 'history',
    routes: [
       ...
    ]
})