title: Problems with URL handling with Spring Boot and Angular 2
body: <p>I am trying to develop an application with Spring Boot for the back end and Angular 2 for the front end, using maven.</p>
  
  <p>The angular 2 front end is in the <code>src/main/resources/static</code> dir of the project.</p>
  
  <p>When I enter the <code>http://localhost:8080/</code> URL in my browser, all is fine: I can access the angular 2 front end, and the front end can communicate with the rest api perfectly. My angular 2 routing works fine: when I click on a link on the front end, I go the right page and the browser url bar shows the right things (ie. <code>http://localhost:8080/documents</code>)</p>
  
  <p>But the problem is when I try to directly write the same URL in the browser. Spring take over the front end and says the is no mapping for <code>/documents</code>.</p>
  
  <p>Is there a way to tell spring boot to only "listen" to <code>/api/*</code> URL and to "redirect" all the others to the front end? </p>
  
  <p>Here is my Spring Controller class:</p>
  
  <pre class="lang-java prettyprint-override"><code>@RestController
  @RequestMapping("/api")
  public class MyRestController {
  
      @Autowired
      private DocumentsRepository documentRepository;
  
      @CrossOrigin(origins = "*")
      @RequestMapping(value = "/documents/list",
              method = RequestMethod.GET,
              produces = "application/json")
      public Iterable&lt;RfDoc&gt; findAllDocuments() {
          return documentRepository.findAll();
      }
  
  }
  </code></pre>
  
  <p>Here is the main application class:</p>
  
  <pre class="lang-java prettyprint-override"><code>@SpringBootApplication
  public class Application {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  
  }
  </code></pre>
  
  <p>Here is my app.route.ts:</p>
  
  <pre class="lang-ts prettyprint-override"><code>import { provideRouter, RouterConfig }  from '@angular/router';
  import { DocumentComponent } from './doc.component';  
  
  const routes: RouterConfig = [
      {
          path: '',
          redirectTo: 'documents',
          pathMatch: 'full'
      },
      {
          path: "documents",
          component: DocumentComponent
      }
  ];
  
  export const appRouterProviders = [
      provideRouter(routes)
  ];
  </code></pre>