Vue.js - 如何删除 hashbang #!从网址?

新手上路,请多包涵

如何从 url 中删除 hashbang #!

我在 vue 路由器文档 ( http://vuejs.github.io/vue-router/en/options.html ) 中找到了禁用 hashbang 的选项,但是这个选项删除了 #! 并且只放了 #

有什么办法可以让网址干净吗?

例子:

不是: #!/home

但是: /home

谢谢!

原文由 DokiCRO 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 539
2 个回答

Vue 3 中,您需要使用 createWebHistory 作为 history 选项。

 import { createRouter, createWebHashHistory } from 'vue-router'

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

Vue 2 中,您需要将 mode 设置为 'history'

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

不过,请确保您的服务器已配置为处理这些链接。 https://router.vuejs.org/guide/essentials/history-mode.html

原文由 Bill Criswell 发布,翻译遵循 CC BY-SA 4.0 许可协议

对于 vue.js 2,请使用以下内容:

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

原文由 Israel Morales 发布,翻译遵循 CC BY-SA 4.0 许可协议

推荐问题