若依框架二级域名部署,及刷新之后404处理
若依框架二级域名部署,及刷新之后404处理
·
第一步先修改程序
-
修改vue.config.js,改为二级域名 例:admin
//publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
publicPath: process.env.NODE_ENV === "production" ? "/admin/" : "/admin/",
-
修改router/index.js,添加 base:"admin"
export default new Router({
mode: 'history', // 去掉url中的#
scrollBehavior: () => ({ y: 0 }),
base: "admin",
routes: constantRoutes
})
-
修改layout/components/Navbar.vue,修改退出操作
this.$store.dispatch('LogOut').then(() => {
// location.href = '/index';
this.$router.push(`/login?redirect=${this.$route.fullPath}`)
})
改完这三处代码修改完成
第二步,nginx部署 这里是最关键的一步
location /admin/ {
alias /mydata/docker/trade/trade_mng/admin/;
try_files $uri $uri/ @dsrouter;
index index.html;
}
location @dsrouter {
rewrite ^/(admin)/(.+)$ /$1/index.html last;
}
重载nginx
nginx -s reload
这里所有的配置就结束了,最关键的点就是 @dsrouter 重定向处理
网上的一些资料 真实离大谱,根本不管有没有效 就乱粘贴代码,搞得非常费劲
这里做一下总结,关键点就是在router的配置 一级域名和二级域名是有区别的,对比如下
#一级域名
location @router {
rewrite ^.*$ /index.html last;
}
#二级域名
location @dsrouter {
rewrite ^/(admin)/(.+)$ /$1/index.html last;
}
更多推荐
所有评论(0)