I have this router:
var campaign = express.Router();
campaign.post('/', function(req, res) {
// enter new subscription here...
res.redirect('welcome');
});
campaign.get('/welcome', function(req, res) {
res.send('welcome!');
});
app.use('/my-newest-campaign', campaign);
The res.redirect
over there does not redirect to /my-newest-campaign/welcome
, but to /welcome
instead. Is this a bug or is there something else that I can do short of res.redirect('/my-newest-campaign/welcome')
to do a router-relative redirect?
See #2086, the redirect is given to the browser as-is, and as such is relative to the actual URL the user is on at the time of the redirect. If you user is at the URL
/foo/bar
and you send backres.redirect('baz')
the browser will send them to/foo/baz
; conversely if the user is at the URL/foo/bar/
and you do the same redirect, the browser will send them to/foo/bar/baz
.The behavior is identical to if you had
<a href="baz">
on that page.