一、配置vue打包參數(shù)
假設(shè)springboot的context-path為/ ,即根路徑,那么我需要為靜態(tài)資源分配一個路由,這里以pages為例,前端vue.config.js配置如下:
publicPath: '/pages/',
outputDir: 'dist',
assetsDir: 'static',
二、springboot系列配置與處理
- 將context-path配置為根路徑/,并設(shè)置shiro等權(quán)限框架對pages權(quán)限攔截的忽略,基于diboot低代碼開發(fā)平臺的項目配置如下:
server.servlet.context-path=/
diboot.iam.anon-urls=/pages/**
-
將前端打包好的dist中的文件夾和文件都放到 springboot項目的 resource/static/pages 目錄下,如下:
image.png 訪問 localhsot:8080/pages/index.html 即可成功
三、訪問路徑優(yōu)化:
上述方案每次必須訪問pages的路由才可以訪問到,那么我們是否可以重定向到這里呢,是可以的。
- 添加以下controller代碼,可從根路徑自動重定向到上述路徑:
@RestController
public class RootRedirectController {
@GetMapping("/")
public void redirect(HttpServletResponse response) throws Exception {
response.sendRedirect("/pages/index.html");
}
}
- 添加權(quán)限框架對根路徑忽略權(quán)限檢查,基于diboot低代碼開發(fā)平臺的項目配置如下:
diboot.iam.anon-urls=/,/pages/**
