赞
踩
本文介绍了在vue3中,如何使用history和hash两种路由模式的方法
使用createWebHistory
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
使用createWebHashHistory
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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。