Skip to content Skip to sidebar Skip to footer

Routing Error With Angular.js And Express

I am trying to do routing with angular.js around /parent root, which works if I'm using anchor links, etc (aka routing handled purely from angular. For instance, a link that has hr

Solution 1:

This is a newly introduced "change of behavior" (or bug).

Try using the base tag :

<base href="/" />

Solution 2:

You're serving your JS/CSS via /parent as well:

... http://localhost:3000/parent/javascripts/jquery.js
                         ^^^^^^^

So if you declare your routes before you declare the express.static middleware, your catch-all route will handle all JS/CSS requests.

You should use a setup similar to this:

// express.static() first...
app.use('/parent', express.static(__dirname + '/public'));

// ...followed by your catch-all route (only one needed)
app.get('/parent*', function(req, res) {
  res.render('main')
});

Post a Comment for "Routing Error With Angular.js And Express"