Routes are not working as expected


Consider the following two routes:

    .get('/permission-names/:id', 'Admin/')
    .get('/permission-names/create', 'Admin/PermissionNameController.create')

If I click on the link /permission-names/create then the Admin/ handler is called instead of create which is incorrect.

Do we need to define routes in a sequential way?


Hey @mjangir! :wave:

This is the expected behaviour.
When you define your routes, you need to be careful on the order.

Your route file is read from the top to bottom and Adonis stops at the first route that matches all criteria.

In your example, created could be the content of the :id variable, so it stops there and calls the handler Admin/PermissionNameController.showwith created as a parameter.

You can avoid that by:

  1. Define your route in a different order (/created comes before /:id);
  2. Use a regex to force :id to be an integer.


Ok I got it. Do we have route validators like putting regex for params?


The current version of the Router uses path-to-regexp to generate the route.

Check their documentation to know how to add regexp to your route.