Hapi-js重定向到另一个带有额外请求数据的路由

Hapi js redirecting to another route with additional request data

本文关键字:请求 数据 路由 重定向 另一个 Hapi-js      更新时间:2023-09-26

在hapi.js中,我可以使用将请求从一条路由重定向到另一条路由

response.redirect('/home')

如何通过重定向发送一些数据?我试着在标题中设置它

response.redirect('/home').header('x-token', token)

但是当该数据到达另一个路由时,该数据将丢失。

您可以使用Yarhttps://github.com/hapijs/yar

request.yar.set('example', { key: 'value' });
response.redirect('/home')

在家路线:

var example = request.yar.get('example'); // this will be "value"