I would like to make an AngularJS application with HTML5-style URLs (i.e. without the # fragment in the URL). So in the routing controller module of my Angular application, I have something like the following:
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*/);
A number of working examples, such as AngularFun , do not use HTML5 mode. For a request like http://localhost:3005/#/1/foo itβs clear that
- the part
http://localhost:3005/ processed by the server / using Express. Express happily serves our Angular -enabled index.html - the
/1/foo route is handled by the Angular router client side
Let's say that our server.coffee looks like a standard, something like below (we serve the static dist directory containing our compiled, mined Angular sources:
express = require 'express' routes = require './routes' dir = "#{__dirname}/dist"
If we use HTML5 mode, our URL http://localhost:3005/#/1/foo becomes http://localhost:3005/1/foo (no more hash # ). This time, the entire URL is intercepted by Express, and it gets confused because we do not define routes other than / .
What we would like to say is that the last part of the URL ( /1/foo ) must be "delegated" to Angular for processing. How can we say that?
source share