I'm searching for a reverse routing feature for Hapijs. For example, if I have the route /route/{param1}/{param2}
named route_name
, I want a function:
reverseRoute('route_name', {param1: 'value1', param2: 'value2'});
which returns /route/value1/value2
I've been googling for a while but cannot find a solution.
Any suggestions?
I put together a plugin called hapi-to that can do this. It manages params, query strings, wildcards and multi-params too.
With your example, it would work like:
request.to('route_name', { params: {param1: 'value1', param2: 'value2'} }
Take a look at the tests for some more examples of how it can be used .