Spring Boot with AngularJS html5Mode

后端 未结 9 2251
长发绾君心
长发绾君心 2020-11-27 04:35

I start my web application with spring boot. It use a simple main class to start an embedded tomcat server:

@Configuration
@EnableAutoConfiguration
@Componen         


        
9条回答
  •  情深已故
    2020-11-27 04:44

    You can forward all not found resources to your main page by providing custom ErrorViewResolver. All you need to do is to add this to your @Configuration class:

    @Bean
    ErrorViewResolver supportPathBasedLocationStrategyWithoutHashes() {
        return new ErrorViewResolver() {
            @Override
            public ModelAndView resolveErrorView(HttpServletRequest request, HttpStatus status, Map model) {
                return status == HttpStatus.NOT_FOUND
                        ? new ModelAndView("index.html", Collections.emptyMap(), HttpStatus.OK)
                        : null;
            }
        };
    }
    

提交回复
热议问题