哈希路由
项目部署在根目录下
publicPath: '/'绝对路径 或者 publicPath: './'相对路径都可以
ngnix配置
`server{
listen 80;
server_name _;
client_max_body_size 100m;
location / {
root /home/user/dist;
index index.php index.html index.htm;
}
location /dev_api{
proxy_pass http://router.anban.shop:38088;
rewrite "^/dev_api(.*)$" $1 break;
}
location /api{
proxy_pass http://172.27.22.177;
}
location /websit {
root /home/user;
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^/(.*) /websit/index.html last;
break;
}
}
location /view {
root /home/user;
index index.php index.html index.htm;
}
location /backend {
root /home/user;
index index.php index.html index.htm;
}
}
`
项目部署在子目录下
publicPath: '/websit'绝对路径 或者 publicPath: './'相对路径都可以
history路由
`const createRouter = () => new VueRouter({
mode: 'history', // require service support
base: '/websit/dist',//需要加后端放项目的路径
scrollBehavior: () => ({ y: 0 }),
routes:constantRoutes
})`
坑一:# 报错Uncaught SyntaxError: Unexpected token<
当我浏览器输入跳转到blog/add时,就不显示内容,报了这个错误。然后我直接重定向到这个页面就行了,但是手动输入这个页面就不行。(作为小白的我觉得这个报错太阴间了),最后网上找到了问题所在,需要使用绝对路径
module.exports = { publicPath: '/', }
配置ngnix
见上图