最近vue项目要部署到服务器,但是发现url中有一个#号,对于我一个强迫症来说是非常难受的,所以找了好多博客,终于解决了,就是在router文件夹下的index.js中的
const router = new Router({
mode: 'hash', //hash改成history就可以解决url中带有#号的问题
scrollBehavior: () => ({ y: 0 }),
isAddDynamicMenuRoutes: false, // 是否已经添加动态(菜单)路由
routes: globalRoutes.concat(mainRoutes)
})
但是随之而来的又是另一个问题,就是不能刷新了,刷新就404,几经查找是因为history模式导致的问题,所以在nginx上配置进行了修改附配置
location / {
//这个必须要
try_files $uri $uri @route;
root /www/jenkins/workspace/dining_room_vue/dist;
index index.html index.htm;
}
//这个必须要
location @route {
rewrite ^.*$ /index.html last;
}
重新加载nginx,问题解决