In Spring Boot, you can configure a catch-all controller like this:
@Configuration public class WebConfig extends WebMvcConfigurerAdapter { @Override public void addViewControllers(ViewControllerRegistry registry) { registry.setOrder(Ordered.LOWEST_PRECEDENCE); registry.addViewController("/**").setViewName("forward:/index.html"); } }
This redirects all requests that are not otherwise processed by index.html. setOrder(Ordered.LOWEST_PRECEDENCE) used to ensure that this forwarding of the entire stop is applied only after no other route is found.
However, now all resource searches are also routed through this view controller (since WebMvcAutoConfiguration checks for the presence of a path template before applying the default resource handler).
One possible fix is to set a static path template in application.properties to enable verification of the file extension:
spring.mvc.static-path-pattern = /**.*
This only works if your angular routes do not contain any extensions. Another way is to completely disable Spring boot resource processing ( spring.resources.addMappings = false ) and substitute your own.
source share