vue项目去掉url中的#引发的血案

最近vue项目要部署到服务器,但是发现url中有一个#号,对于我一个强迫症来说是非常难受的,所以找了好多博客,终于解决了,就是在router文件夹下的index.js中的

const router = new Router({
  mode: 'hash',  //hash改成history就可以解决url中带有#号的问题
  scrollBehavior: () => ({ y: 0 }),
  isAddDynamicMenuRoutes: false, // 是否已经添加动态(菜单)路由
  routes: globalRoutes.concat(mainRoutes)
})

nginx中的配置:

location / 
{  
    //这个必须要
    try_files $uri $uri @route;
    root /www/wwwroot/www.mrzhao520.cn/dist;
    index  index.html index.htm;
}
//这个必须要
location @route { 
    rewrite ^.*$ /index.html last;
}

原文链接:https://blog.csdn.net/qq_35818188/article/details/108067287

posted @ 2021-07-01 16:52  做个笔记  阅读(406)  评论(0编辑  收藏  举报