I am serving an SPA made with create-react-app and react-router using Spring Boot 2.1.0 with this configuration
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/**/{path:[^\\.]+}")
.setViewName("forward:/");
}
}
Basically what it does is always serve index.html unless there's a period in the path. I would like to align this with create-react-app's provided .htaccess
. How can I make Spring Boot match this functionality?
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]