【发布时间】:2018-02-10 13:05:01
【问题描述】:
我正在构建 spring 网站,该网站在子路由下反应单页应用程序,我当前的 url 结构应该看起来像
localhost/admin/** => react app
localhost/** => spring thymeleaf/rest/websocket app for everything else
react app mapping:
localhost/admin/static/** => static react files
localhost/admin/** => react index.html for everything else
Example of project resources structure:
resources/
admin/ <= my admin react files is here
index.html
static/ <= react css, js, statics
templates/ <= thymeleaf templates
static/ <= theamleaf static
...
所以我需要为每个 url 路由及其子路由转发 index.html 文件。除了静态文件之外,基本上都是单页应用程序
看起来像一个常见的任务,这是我已经尝试过的一些事情:
项目 spring + react + gradle 如何构建项目的完整工作演示以及为什么我不能将 react 文件放在不同的目录中(例如 /resources/static):https://github.com/varren/spring-react-example
不能将forward:/admin/index.html 用于/admin/**,因为这将创建递归,因为admin/index.html 也在admin/** 之下并且必须以某种方式拦截admin/static/**。
不能在
WebMvcConfigurerAdapter 中使用addResourceHandlers
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/admin/**")
.addResourceLocations("classpath:/admin/");
}
index.html 仅映射到 /admin/index.html url,并且此选项几乎可以工作,但前提是您从 localhost/admin/index.html 访问 react 应用程序
看到this 和this 和this 和许多其他链接,我也有一些解决方案,但也许有我看不到的通用选项
【问题讨论】:
标签: java spring reactjs spring-mvc single-page-application