title: How Can Spring MVC Handle Requests to URLs Generated by the Angular Router?
body: <p>I have a Spring (v, 4.3.2 &amp; Java 8) application that serves up an Angular2 single page application front end that has multiple routes (say <code>/foo</code>, <code>/bar</code> and <code>/baz</code>, one of which requires a parameter to render (<code>/baz/x</code> where x is the identifier of the resource to retrieve). </p>
  
  <p>The html is served up with a standard Spring MVC <code>@Controller</code>:</p>
  
  <pre><code>@RequestMapping(value = {"/", "/foo", "/bar", "/baz/{id}"}, method = RequestMethod.GET)
  public String index(@PathVariable Optional&lt;String&gt; id) {
      return "index";
  }
  </code></pre>
  
  <p>and views are resolved using:</p>
  
  <pre><code>@Bean
  public InternalResourceViewResolver internalResourceViewResolver() {
      InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
      viewResolver.setPrefix("WEB-INF/pages/");
      viewResolver.setSuffix(".jsp");
      return viewResolver;
  }
  </code></pre>
  
  <p>If the browser reloads from the <code>/</code>, <code>/foo</code> or <code>/bar</code> routes, the controller properly returns the <code>index</code> page and angular resolves the view for the route as expected. However, if the browser reloads from one of the <code>baz</code> routes that contain a paramenter, the server prepends <code>baz</code> to the  resource path (e.g. <code>/baz/WEB-INF/pages/index.jsp</code>) which, results in a 404 error.</p>
  
  <p>I've tried refactoring the <code>baz</code> request mappings info into an annotation on a distinct (identical) method and using wildcards in the request mapping (e.g. <code>/**</code> and <code>baz/*</code> ), but always get the same result. Regardless of the request mapping, Spring seems unaware that it is appending <code>baz</code> into the path, as the logs contain:</p>
  
  <pre><code>DEBUG: org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.InternalResourceView: name 'index'; URL [WEB-INF/pages/index.jsp]] in DispatcherServlet with name 'dispatcher'
  DEBUG: org.springframework.web.servlet.view.InternalResourceView - Forwarding to resource [WEB-INF/pages/index.jsp] in InternalResourceView 'index'
  DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request
  </code></pre>
  
  <p>Any help on this would be appreciated.</p>