若依框架二级域名部署,及刷新之后404处理

第一步先修改程序

  1. 修改vue.config.js,改为二级域名 例:admin


//publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
publicPath: process.env.NODE_ENV === "production" ? "/admin/" : "/admin/",
  1. 修改router/index.js,添加 base:"admin"

export default new Router({
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  base: "admin",
  routes: constantRoutes
})
  1. 修改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;
    }

  • 7
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值