vue3.0中改变router为hash或者history

前言:

       在这里我们分析总结下vue2.0和vue3.0 改变router为hash或者history 的方法。

vue2.0

history:

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

hash:

const router = new VueRouter({
  mode: 'hash',  //或者把这句话注释,默认就是hash
  routes: [...]
})

vue3.0

history: 引入-createWebHistory

import { createRouter, createWebHistory} from 'vue-router';
const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
});

hash: 引入-createWebHashHistory 

import { createRouter, createWebHashHistory } from 'vue-router';
const router = createRouter({
  history: createWebHashHistory(),
  routes
});

猜你喜欢

转载自blog.csdn.net/qq_41619796/article/details/114284350