修改前端src/router/index.js中,开启model为history方式
const createRouter = () => new Router({
mode: 'history', // require service support
scrollBehavior: () => ({ y: 0 }),
routes: constantRoutes
})后端修改nginx配置
vim /usr/local/nginx/conf/vhost/log.conf
添加try_files配置,注意先注释掉“try_files $uri =404;”这句
location ~ [^/]\.php(/|$)
{
# comment try_files $uri =404; to enable pathinfo
# try_files $uri =404;
try_files $uri $uri/ /index.html;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
#include pathinfo.conf;
}关于以上官网建议配置location /,但实测配置location ~ [^/]\.php(/|$)也是可行的
完成保存后重启nginx
service nginx restart