如何从vue js中的url中删除hasbang

Shr*_*shi 3 vue.js

我想从 vue js 中的 url 中删除 hashbang 我正在尝试 mode:'history', hashbang:false, history:true, linkActiveClass: "active", 但仍然在 url 中获取哈希

kan*_*ano 6

初始化 Vue 路由器时,这是使其工作的最少代码:

const router = new Router({
  mode: 'history'
})
Run Code Online (Sandbox Code Playgroud)

然后,您需要router在创建时将路由器实例(此处)传递给您的 Vue 实例:

new Vue({
  el: '#app',
  components: { App },
  template: `<App/>`,
  router
})
Run Code Online (Sandbox Code Playgroud)

仅使用此设置,vue-router应该已经可以在历史模式下工作。但是,很可能您还想向路由器实例添加路由:

const router = new Router({
  mode: 'history',
  routes: [...]
})
Run Code Online (Sandbox Code Playgroud)

如果您可以共享一些代码,那么我们将在很大程度上帮助您进一步帮助您。

现在,您还可以查看一个小型路由器示例(注意浏览器 URL 中的路由如何更改为/foo,然后更改为/bar,没有散列)。