Express router conflicting with Backbone pushstate

An Express / route serves my Backbone's app index.html.

I'm using pushstate in Backbone but the routes that Backbone should handled are being handled by express, giving 404 responses.

How can I setup Express to serve the index.html but to delegate other routes to Backbone?

In this situation you have multiple options:

  1. You can have a server that handles the same routes as the client does and returns the same results. It is hard to implement but it gives a good url. Github did this.

  2. Always return index.html and handle the route client side. (That is somewhat ugly and hard to maintain)

  3. Don't use pushstate. Amen.

You can use /* approach. Just have it as the last route. That way the other routes such as any service API calls will be matched before the catch all route of /* is matched. This is also how Backbone handles its routes.