I am using Express, which loads AngularJS from a static directory. I usually ask for http://localhost/ , in which Express serves me index.html and all the correct Angular files, etc. In my Angular app, I have these route settings that replace the contents in ng-view :
$routeProvider.when('/', { templateUrl: '/partials/main.html', controller: MainCtrl, }); $routeProvider.when('/project/:projectId', { templateUrl: '/partials/project.html', controller: ProjectCtrl, }); $locationProvider.html5Mode(true);
On my main page, I have a link to <a href="/project/{{project.id}}"> , which will successfully download the template and redirect me to http://localhost/project/3 or any other identifier, which I indicated. The problem is that when I try to direct my browser to http://localhost/project/3 or refresh the page, the request is sent to the Express / Node server, which returns Cannot GET /project/3 .
How do I set up Express routes for this? I assume this will require the use of $location in Angular (although I would prefer to avoid the ugly searches and # hashes that they use), but I don't know how to start setting up Express routes to handle this.
Thank.
Wind Up Toy Nov 04 '12 at 19:52 2012-11-04 19:52
source share