vue3中路由hash与History的设置
文章目录
- vue3中路由hash与History的设置
- history 路由
- hash 路由
vue3中路由hash与History的设置
history 路由
history 关键字:createWebHistory,修改router/index
URL格式:hhh.com/user/id。相比hash模式更加好看。
import { createRouter, createWebHistory } from 'vue-router'
const routes = [ {
path: '/userinfo',
name: 'UserInfo',
component: () => import('../views/UserInfo.vue')
}]
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
})
export default router
hash 路由
hash 关键字:createWebHashHistory
URL格式:www.abc.com/#/vue,它的hash值就是#/vue。
import { createRouter, createWebHashHistory } from 'vue-router'
const routes = [{
path: '/userinfo',
name: 'UserInfo',
component: () => import('../views/UserInfo.vue')
}]
const router = createRouter({
history: createWebHashHistory(),
routes
})
export default router