vue中路由切换history模式

这个是 vue3.0x 的写法

// 在最顶部引入createWebHistory 
import { createRouter, createWebHistory,  } from 'vue-router'  

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  { .... }
]

const router = createRouter({
  history: createWebHistory(),  // 在调用 createWebHistory() 即可
  routes
})

然后 vue2.0.x 的写法

// vue2.0.x 写法比较简单
import VueRouter from 'vue-router'

const router = new VueRouter({
  mode: "history",
  routes
})

Vue Router 官方网址 history 说明


版权声明:本文为bobo979520原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。