Hello, sorry to bother you, but could you tell me if it is possible to build a URL address in which the :city parameter will specify different cities, for example: /fly-to-amsterdam or /fly-to-paris
I tried to make a router like /fly-to-:city, but it works as a static address.
I tried to use wildcard params and then define the parameter using the regular expression router.get('*', (ctx) => {...}). This works but breaks the static.
The /fly-to/:city format works, but does not suit the customer.
Join The Discussion! (3 Replies)
Please sign in or sign up for free to join in on the dicussion.
tomgobich
Hi Oliver!
Partial route parameters, like
/fly-to-:city
aren't supported by the AdonisJS Router at present. However, you can use a vague route parameter in conjunction with a route param validator to make this work.The
where
here is applying a validator to the route parameter, stating that the parameter should start with "fly-to-" in order for the route to match the definition.We have a lesson where we cover this using user profiles in our Let's Learn AdonisJS 6 series if you'd like to learn more!
Please sign in or sign up for free to reply
oliverwhite
Thank you very much! Your answer solved my problem.
Please sign in or sign up for free to reply
tomgobich
Anytime! Awesome, glad to hear you’re all set Oliver!
Please sign in or sign up for free to reply