0

I have a spring boot application which is serving the AngularJS app within it. When I try to navigate using buttons, links etc everything is working good. But when try to refresh the page with F5, Spring container returns 404. Any clue about that? Below is Web configuration for the boot application.

@Configuration
public class UIWebConfig implements WebMvcConfigurer
{
  @Override
  public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/").setViewName("forward:/index.html");
    registry.addViewController("/admin").setViewName("forward:/admin/index.html");
  }

  @Override
  public void configurePathMatch(PathMatchConfigurer configurer) {
    configurer.setUseSuffixPatternMatch(false);
  }

  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry)
  {
    registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
  }
}
Mahesh
  • 91
  • 1
  • 2
  • 9
  • Possible duplicate of [AngularJS routing 404 error with HTML5 mode](https://stackoverflow.com/questions/44271461/angularjs-routing-404-error-with-html5-mode/) – georgeawg Aug 03 '18 at 14:37

1 Answers1

1

Sorry, can't make comments so I have to post here :(

Could it be this line of code ??

registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");

I believe you're missing a '.' before the /static/ directory so the IDE knows you're ussing a relative (to your computer) directory.

Try it like this:

registry.addResourceHandler("/**").addResourceLocations("classpath:./static/");

Sorry if I'm wrong ! I'll delete it if so. Just trying to help :)

  • Basically when I navigate through buttons or links from the web pages it’s working good. If I press F5 after navigating to a page, I can see 404 error. – Mahesh Aug 03 '18 at 20:51