title: How to have Express routing work with Angular routing with HTML5 style URLs?
body: <p>I would like to make an AngularJS app with HTML5-style URLs (i.e. with no <code>#</code> fragment in the URL). Thus in the routing controller module of my Angular app I've got something like the following:</p>
  
  <pre><code>angular.module('app').config(['$routeProvider','$locationProvider',function($routeProvider,$locationProvider) {
      $locationProvider.html5Mode(true)
  ...
  }
  
  $routeProvider
  .when('/1/:param', /* do something */)
  .when('/2/:param', /* do something else */)
  .when('/3/:param', /* do something else again*/);
  </code></pre>
  
  <p>A number of working examples like <a href="https://github.com/CaryLandholt/AngularFun" rel="nofollow">AngularFun</a> don't use HTML5 mode. For a request like <code>http://localhost:3005/#/1/foo</code>, it's clear that</p>
  
  <ul>
  <li>the <code>http://localhost:3005/</code> part is handled server-side <code>/</code> by Express. Express happily serves our Angular-enabled <code>index.html</code></li>
  <li>the <code>/1/foo</code> route is handled client-side by Angular's router</li>
  </ul>
  
  <p>Say our <code>server.coffee</code> looks, as standard, something like the below (we serve the static <code>dist</code> directory that contains our compiled, minified Angular sources:</p>
  
  <pre><code>express = require 'express'
  routes = require './routes'
  dir = "#{__dirname}/dist"            # sources live here
  port = process.env.PORT ? process.argv.splice(2)[0] ? 3005
  app = express()
  
  app.configure -&gt; 
      app.use express.logger 'dev'
      app.use express.bodyParser()
      app.use express.methodOverride()
      app.use express.errorHandler()
      app.use express.static dir       # serve the dist directory
      app.use app.router
      routes app, dir                  # extra custom routes
  </code></pre>
  
  <p>If we do use HTML5 mode, our URL <code>http://localhost:3005/#/1/foo</code> becomes <code>http://localhost:3005/1/foo</code> (no more hash <code>#</code>). This time, the entire URL is intercepted by Express, and it gets confused because we don't define routes other than <code>/</code>.</p>
  
  <p>What we would really like to say is that the latter part of the URL (<code>/1/foo</code>) should be 'delegated' to Angular for handling. How can we say this?</p>