Angular and Express routing

Add these routes to your express server

app.get('/partials/:filename', routes.partials);
app.use(routes.index);

Then in routes.js

exports.partials = function(req, res){
  var filename = req.params.filename;
  if(!filename) return;  // might want to change this
  res.render("partials/" + filename );
};

exports.index = function(req, res){
  res.render('index', {message:"Hello!!!"});
};

This will make sure that express returns rendered templates when making requests to partials/index and partials/about.

Here’s a gist: https://gist.github.com/4277025

Leave a Comment