1

I am trying to pass an index value, for an array, into a route, so I can use the id to load a specific object into a detail view.

Controller that injects the index and changes path

location.path('/detail/'+index);

$routeProvider that handles the detail routing

.when('/detail/:index', { 
    controller: DetailViewCtrl, templateUrl: 'partials/detail' 
});

Express script that handles the partial loading

app.get('/partials/:partial', function(req, res) {
    return res.render('partials/' + req.params['partial']);
};

If I pass in an index of 5 then I expect the URL to look like "localhost:3000/detail/5", and I do get that in my browser but the server returns a 404 error where is was trying to look for some weird URL "localhost:3000/detail/partials/detail." I have no clue where the "detail " that is added before the partial is coming from.

It would be nice to know what is happening behind the scenes and how to fix the problem. How can I pass custom variables in the route and not have express freak out?

1 Answer 1

2

Prepend the templateUrl with /:

.when('/detail/:index', { 
   controller: DetailViewCtrl, 
   templateUrl: '/partials/detail' 
});

or insert the base tag under the HTML head element as in:

<base href="/" />
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.