1

I'm trying to set up some routes with parameters in an AngularJS app backed by a node.js server using express. Node is set up to route everything that isn't explicitely found to a catch all:

app.use(express.bodyParser());
app.use(app.router);
app.use(express.static(__dirname + "/public"));
app.use(function(request, response)
{
    console.log("catch all");
    writeFile("/public/index.htm", request, response);
});

And Angular has routes defined with 0-2 parameters:

$routeProvider
.when("/",
{
    templateUrl: "home.htm"
})
.when("/otherpage",
{
    templateUrl: "otherpage.htm"
})  
.when("/otherpage/:Var1",
{
    templateUrl: "otherpage.htm"
})  
.when("/otherpage/:Var1/:Var2",
{
    templateUrl: "otherpage.htm"
})
.otherwise(
{
    templateUrl: "home.htm"
});

$locationProvider.html5Mode(true);

/otherpage works, but while /otherpage/123 hits the catch all (I can see the console message), it crashes in the browser. Nothing is rendered and then Chrome says that it has a problem (and IE renders nothing just sits there).

I can understand the parameter not being passed, but why isn't the route at least happening without it? What do I need to do to set up URL parameters with express.js and AngularJS?

You can download the project here, if you want to examine it.

Thanks in advance.

1
  • I would highly recommend using Brian Fords excellent Angular-Express-Seed as your starting point. Check out github.com/btford/angular-express-seed. Being new to both Node and Angular, I've used this on my own project and found it to be invaluable. Commented Apr 4, 2013 at 10:13

1 Answer 1

2

The problem was that I wasn't preceding my templateUrls with a foreslash. Changing them to this:

.when("/otherpage/:Var1/:Var2",
{
    templateUrl: "/otherpage.htm"
})

Worked perfectly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.