I\'m developing a spring backend for a react-based single page application where I\'m using react-router for client-side routing.
Beside the index.html page the back
Avoid @EnableWebMvc
By default Spring-Boot serves static content in src/main/resources:
Take a look at this and this;
Or keep @EnableWebMvc and override addViewControllers
Did you specify @EnableWebMvc ? Take a look a this: Java Spring Boot: How to map my app root (“/”) to index.html?
Either you remove @EnableWebMvc, or you can re-define addViewControllers:
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/index.html");
}
Or define a Controller to catch /
You may take a look a this spring-boot-reactjs sample project on github:
It does what you want using a Controller:
@Controller
public class HomeController {
@RequestMapping(value = "/")
public String index() {
return "index";
}
}
Its index.html is under src/main/resources/templates