vue项目去除访问路径中的#号(Vue 访问路径开启history 模式)
最近学习vue过程中,发现路径当中总是存在一个#号,比如这个:
这种情况是因为在入口js文件中,如果你不更改设置的话,vue会默认使用hash模式,该模式下回将路径格式化为 # 开头。
如果需要美化路径,可以更改模式为 history :
router 里面的index.js配置里面
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
const routes = [
{
path: '/about',
name: 'about',
meta: {
title: '关于',
auth: false
},
component: () => import(/* webpackChunkName: "about" */ '../view/About.vue')
}
]
const router = new Router({
mode: 'history',
base: process.env.BASE_URL,
routes
})
export default router