My application is based on NodeJs & AngularJs SPA. I ran into routing issues. The application is complex. To make it easier to explain the problem , I created a trivial todo application.
Node server code ( server.js)
var express = require('express'),
path = require('path'),
publicPath = path.normalize(__dirname + '/public'),
Todos = require('./Todo');
var app = express();
app.configure(function() {
app.use(express.logger('dev'));
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.session({secret: 'This is Top secret'}));
app.use(express.static(publicPath));
});
app.get('/api/Todos',Todos.getTodos);
app.get('/api/Todos/:id',Todos.getById);
app.put('/api/Todos/:id', Todos.update);
app.post('/api/Todos/:id', Todos.create);
app.delete('/api/Todos/:id', Todos.delete);
app.all('/api/*', function(req, res) {
res.send(404);
});
app.get('*', function(req, res) {
res.sendfile(publicPath+'/index.html');
});
app.listen(3000);
console.log('Listening on port 3000');
AngularJs routing related code ( app.js)
angular.module('app', ['ngRoute']);
angular.module('app').config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/', { templateUrl: 'views/home.html', controller: 'HomeCtrl'})
.when('/Todos', { templateUrl: 'views/todo.list.html', controller: 'TodoListCtrl' })
.when('/Todos/Edit/:id', { templateUrl: 'views/todo.edit.html', controller: 'TodoEditCtrl' })
.otherwise({ redirectTo: '/' });
$locationProvider.html5Mode(true);
});
In this /Todos route works but /Todos/Edit/:id route does not work. If I navigate to that route through href / ng-href the browser hangs and later it crashes.
I'm clueless. Kindly guide me. Thanks in advance.