I need to perform a redirect from a route to another route and pass some data to the latter route. I'm using query strings to pass data between routes, but I'd like to avoid this.
My current solution
I'm using res.redirect
and url.format()
to pass the data between routes as a query string.
Current code:
app.get('x-foo', (req, res) => {
const foo = '1234';
res.redirect(url.format({
pathname: 'x-bar',
query: {
foo: foo
}
}));
})
app.get('x-bar', (req, res) => {
console.log(req.query.foo); // logs '1234'
res.render(...some page)
});
Why I'd like to avoid it
I'd like to avoid this method because I don't want the query string to appear in the user's browser.
Is there any other way to do this that doesn't involve query strings?