1

I have the following problem. In my node.js application, the user clicks on link which send it by get to my app.js. The Link is a filename. In my app.js I can read the param, but the browser still tries to open the file in the browser

app.get('/files/:file', function(req, res) {
    console.log('Would handle ' + req.params.file);
});

So what I have to do to stop the browser opening the link?

4

1 回答 1

1

As stated in the comment above. You can use:

app.get('/files/:file', function(req, res) {
    console.log('Would handle ' + req.params.file);
    res.redirect('back');
});

You can read more information about this on the Express - api reference page. The res.redirect('back') will redirect to the referring page; if there is no referring page, it will default to '/'. Hope this information helps.

于 2013-09-25T03:55:55.103 回答