Serving angular2 content from Spring Boot application

Recently I had to ship an Angular2/Angular4 application within a Spring boot WAR packaged application and I was having some issues when dealing with the the urls in the angular routes, since it goes through the DispatcherServlet I was getting 404 all over the place

There are a few ways to handle this, below is my preferred solution :


@Controller
public class Angular2ViewController {


    @RequestMapping({"/books", "/login", "/admin", "/logout", "/configure"})
    public String index() {
        return "forward:/index.html";
    }

}

There you go, as easy as that

The inconvenience about this solution is that you have to maintain a set of urls in your controller also