vue3切换路由模式——Hash 、histoary

1、history模式

使用createWebHistory

bash 复制代码
import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('../views/About.vue')
  }
]
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})
export default router

2、hash模式

使用createWebHashHistory

bash 复制代码
import { createRouter, createWebHashHistory } from 'vue-router'
import Home from '../views/Home.vue'
 
const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('../views/About.vue')
  }
]
const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes
})
export default router

综上所述:

history 对应 createWebHistory

hash 对应 createWebHashHistory

相关推荐
Daniel李华14 小时前
echarts使用案例
android·javascript·echarts
北原_春希14 小时前
如何在Vue3项目中引入并使用Echarts图表
前端·javascript·echarts
JY-HPS14 小时前
echarts天气折线图
javascript·vue.js·echarts
尽意啊14 小时前
echarts树图动态添加子节点
前端·javascript·echarts
吃面必吃蒜14 小时前
echarts 极坐标柱状图 如何定义柱子颜色
前端·javascript·echarts
O_oStayPositive14 小时前
Vue3使用ECharts
前端·javascript·echarts
竹秋…14 小时前
echarts自定义tooltip中的内容
前端·javascript·echarts
宝贝露.14 小时前
Axure引入Echarts图无法正常显示问题
前端·javascript·echarts
人良爱编程14 小时前
Hugo的Stack主题配置记录03-背景虚化-导航栏-Apache ECharts创建地图
前端·javascript·apache·echarts·css3·html5
来颗仙人掌吃吃14 小时前
解决Echarts设置宽度为100%发现宽度变为100px的问题(Echarts图标宽度自适应问题)
前端·javascript·echarts