做平面的公司网站快速建站
具体步骤
Vue 中配置
(1)更改router模式,添加前缀
位置:router文件夹下面的index.js
const router = new Router({base: '/nhtjfx/', // 路由前缀mode: 'history', // 采用history模式URL的路径才跟配置的对应上,不然URL是先加/#再追加配置的地routes:[...]});
(2)实现静态文件加前缀
位置:vue.config.js
module.exports = {publicPath: '/nhtjfx/',
}
(3)nignx配置
server {listen 8088;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location /nhtjfx/ {alias /usr/local/linewell/web/nhjcfx/front/nhtjfx/;index index.html;try_files $uri $uri/ /nhtjfx/index.html;}#location / {# root /usr/local/linewell/web/nhjcfx/front/nhtjfx;#vue前端项目打包后放在这里 # root /usr/local/linewell/web/nhjcfx/front/build;# index index.html index.htm;#这个index.html 是上面dist目录下的index.html# try_files $uri $uri/ /index.html; # 解决刷新出现404 # }#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}