Spring Boot with AngularJS html5Mode

后端 未结 9 2278
长发绾君心
长发绾君心 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条回答
  •  萌比男神i
    2020-11-27 04:42

    I finally get my Angular 5 application working with spring boot with or without spring-boot-starter-tomcat as provided (embedded) or not!

    /**
     * Needed for html5mode (PathLocationStrategy in Angular). Every path except api/* and resources (css, html, js, woff, etc..)
     * should be redirect to index.html and then should angular managed routes (which could be correct or non existing).
     */
    @RestController
    @RequestMapping
    public class ForwardController {
    
        @GetMapping(value = "/**/{[path:[^\\.]*}")
        public ModelAndView forward() {
            return new ModelAndView("/index.html");
        }
    }
    

提交回复
热议问题