(history:在开发模式下,就算没有配nginx也是可以运行的,在打包后的模式下,没有后台配置的话,刷新就找不到页面了)
1、vue中
const router = new VueRouter({
mode: 'history', // 模式选择history
routes: [...]
})
2、nginx
location / {
root D:/phpstudy_pro/WWW/ant-design-vue-pro-master/dist; // 自己打包后的文件目录
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
说明:假设当前的访问路径为:http://127.0.0.1/abc/index.html
try_files // 重定向
$uri: (代表的是目录),首先查找abc目录下的index.html,如果找到则返回,
$uri/ : (代表的是目录),接着查找abc/ 目录下的子目录,如果找到则返回,
/index.html : 代表前面都找不到的情况,直接返回index.html