I had a similar problem with my SpringBoot 2 and Angular6 application. I implemented an interface WebMvcConfigurerto override addResourceHandlers()and redirect to index.htmlwhen addResourceHandlers()no mappings were found in the controllers . this can be done in Spring boot 1.5.x, extending the (now obsolete) class WebMvcConfigurerAdaptor. this is discussed in detail in this stackoverflow: fooobar.com/questions/1017173 / ...
I put a built-in corner application in this place target/classes/staticusing the outputPathfield in angular.json(earlier .angular-cli.json). Here is a sample code:
@Configuration
public class MyAppWebMvcConfigurer implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**/*")
.addResourceLocations("classpath:/static/")
.resourceChain(true)
.addResolver(new PathResourceResolver() {
@Override
protected Resource getResource(String resourcePath, Resource location) throws IOException {
Resource requestedResource = location.createRelative(resourcePath);
return requestedResource.exists() && requestedResource.isReadable() ? requestedResource : new ClassPathResource("/static/index.html");
}
});
}
}
source
share