美文网首页收藏springbootVUE
Vue项目发布到springboot中的系列配置

Vue项目发布到springboot中的系列配置

作者: fresh_ozone | 来源:发表于2021-11-16 09:38 被阅读0次

一、配置vue打包参数

假设springboot的context-path为/ ,即根路径,那么我需要为静态资源分配一个路由,这里以pages为例,前端vue.config.js配置如下:

  publicPath: '/pages/',
  outputDir: 'dist',
  assetsDir: 'static',

二、springboot系列配置与处理

  1. 将context-path配置为根路径/,并设置shiro等权限框架对pages权限拦截的忽略,基于diboot低代码开发平台的项目配置如下:
server.servlet.context-path=/
diboot.iam.anon-urls=/pages/**
  1. 将前端打包好的dist中的文件夹和文件都放到 springboot项目的 resource/static/pages 目录下,如下:


    image.png
  2. 访问 localhsot:8080/pages/index.html 即可成功

三、访问路径优化:

上述方案每次必须访问pages的路由才可以访问到,那么我们是否可以重定向到这里呢,是可以的。

  1. 添加以下controller代码,可从根路径自动重定向到上述路径:
@RestController
public class RootRedirectController {

    @GetMapping("/")
    public void redirect(HttpServletResponse response) throws Exception {
        response.sendRedirect("/pages/index.html");
    }
}
  1. 添加权限框架对根路径忽略权限检查,基于diboot低代码开发平台的项目配置如下:
diboot.iam.anon-urls=/,/pages/**

相关文章

网友评论

    本文标题:Vue项目发布到springboot中的系列配置

    本文链接:https://www.haomeiwen.com/subject/jpthtrtx.html