title: Spring Boot with redirecting with single page angular2
body: <p>I have a single page Angular app with Spring Boot. It looks like the following:</p>
  
  <pre><code>src
    main
    java
      controller
         HomeController
         CustomerController
         OtherController
    webapp
      js/angular-files.js
      index.html
  </code></pre>
  
  <p>Spring boot correctly defaults to webapp folder and serves index.html file.  </p>
  
  <p>What I am looking to do is:</p>
  
  <ol>
  <li><p>For every local REST request <em>not</em> starting with <code>/api</code> overwrite and redirect to default webapp/index.html.  I plan to serve anything <code>/api</code> to the spring controllers.</p></li>
  <li><p>Is there a way to prefix all controllers with API so that I do not have to write API every time?
  e.g. </p>
  
  <p>@RequestMapping("/api/home") can write shorthand in code  @RequestMapping("/home")</p></li>
  </ol>
  
  <p>or </p>
  
  <pre><code>@RequestMapping("/api/other-controller/:id") can write shorthand  @RequestMapping("/other-controller/:id")
  </code></pre>
  
  <p>I'm looking for every API request, e.g. 1) <a href="http://localhost:8080/api/home" rel="noreferrer">http://localhost:8080/api/home</a> keep API with API and resolve to correct controller and return JSON, however if someone enters a URL like <a href="http:///localhost/some-url" rel="noreferrer">http:///localhost/some-url</a>  or <a href="http:///localhost/some-other/123/url" rel="noreferrer">http:///localhost/some-other/123/url</a> then it will serve the index.html page and keep the URL.</p>
  
  <p><a href="https://i.stack.imgur.com/wVMZ5.png" rel="noreferrer"><img src="https://i.stack.imgur.com/wVMZ5.png" alt="enter image description here"></a></p>
  
  <p>Alternative ways to do it: try adding #ErrorViewResolver: 
  <a href="https://stackoverflow.com/questions/38516667/springboot-angular2-how-to-handle-html5-urls">Springboot/Angular2 - How to handle HTML5 urls?</a></p>