view raw
rudolfschmidt rudolfschmidt - 9 months ago 454
AngularJS Question

Spring Boot with AngularJS html5Mode

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

public class Application {

public static void main(String[] args) {, args);


I want to configure the server in the way that he can handle angularjs html5mode that will be activated with


Relevant postings from other users shows that you need to redirect to the root. the html5 mode remove the hashbag from the url. If you refresh the page the server doesnt find the page cause he do not handle the hash. see: AngularJS - Why when changing url address $routeProvider doesn't seem to work and I get a 404 error


I found a solution I can live with it.

public class ViewController {

    public String index() {
        return "index";

    public String app() {
        return "index";

The angularjs app has to be under the subdomain app. If you do not want that you could create a subdomain like that mapps to your subdomain app. With this construct you have no conflicts with webjars, statis content and so on.