In my node app I want to route and indefinite number of paths in a url to one template, and then present to that template an array of all the paths.
For example, I want to allow the routes '/',/foo/,/foo/bar/ and /foo/bar/[...etc] all to point to the same view template with the paths split into an array, ie: [], ['foo'], ['foo','bar'], respectively.
This code, seems to answer the first part of the question:
app.route('/*')
.get(function (req, res) {
res.render('index',{
paths: req.params[0]
});
});
But when I loop through the paths variable in my template, each letter is out put individually rather than path by path.
Is this possible? And if so, some help would be greatly appreciated.
That's because you're looping through a string so it's pulling each character from that string. Just change req.params[0] to req.params[0].split('/').
http://localhost:4000/my/full/path will give you [ 'my', 'full', 'path' ] as the paths variable in your view.