直接上代码,自己的环境一切正常,有问题可以讨论。
路由设置:
const router=newVueRouter({
mode:'history',
base:'/information', //项目在nginx子目录的时候配置
routes:routes
});
router.beforeEach((to, from, next) => {
if(to.matched.length===0) {//如果未匹配到路由
from.fullPath ? next(from.fullPath) : next('/information/');//如果上级也未匹配到路由则跳转登录页面,如果上级能匹配到则转上级路由
}else{
next();//如果匹配到正确跳转
}
});
nginx配置:
location ^~/information/ {
try_files $uri $uri/ /information/index.html;
root /data/www;
index index.html;
}
注:主要看粗体部分就可以了