nginx配置若依框架二级路径,页面退出出现404问题

nginx配置 

location /gongdan {
   alias html/gongdan;
   try_files $uri $uri/ @router;
   index index.html;
}
location @router {
   rewrite ^/(gongdan)/(.+)$ /$1/index.html last;
}
location /gongdan-api {
   proxy_pass /*后端地址*/;
}

若依vue配置

vue.config.js

  publicPath: process.env.NODE_ENV === "production" ? "/gongdan/" : "/",

 src/layout/components/Navbar.vue

找到下面这几行代码修改为

 async logout() {
      this.$confirm("确定注销并退出系统吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$store.dispatch("LogOut").then(() => {
            // location.href = "/index";
            // 若依nginx 配置二级路径存在 location 404的问题
            this.$router.push(`/login?redirect=${this.$route.fullPath}`);
          });
        })
        .catch(() => {});
    },

src/utils/request.js

    if (code === 401) {
      if (!isRelogin.show) {
        isRelogin.show = true;
        MessageBox.confirm(
          "登录状态已过期,您可以继续留在该页面,或者重新登录",
          "系统提示",
          {
            confirmButtonText: "重新登录",
            cancelButtonText: "取消",
            type: "warning",
          }
        )
          .then(() => {
            isRelogin.show = false;
            store.dispatch("LogOut").then(() => {
              // 若依nginx 配置二级路径存在 location 404的问题
              // location.href = "/index";
              location.href = "/gongdan/index";
            });
          })
          .catch(() => {
            isRelogin.show = false;
          });
      }

 这个location.href 和vue-router 可能会出现冲突,配置二级路径的时候应该要注意。

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值