Named middlewares are called for all matching routes


I have the following routes:

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

When I call the route/permission-names/create, the middleware isRoutePermitted is called twice which means all the matching routes /permission-names and /permission-names/create.

How to exact match the route like if I call the create route, then the middleware should be called only once. Actually I want to call this middleware right before it hits the handler.


Hey @mjangir! :wave:

How do you know that the middleware has been called twice?

Please, ensure that you are not also defining this middleware in a Route Group or as a global middleware.


I mean to say, all the matching routes handlers are called which is the problem. For example, If I’ve two following routes:

Route.get('/permission-names', 'Admin/PermissionNameController.index')
Route.get('/permission-names/12', 'Admin/')

With the above case, if I hit /permission-names/12 then the first route handler shouldn’t call but its happening right now.


I cannot reproduce your issue and your code seems fine.

Please, create a repository with the minimum amount of code to reproduce the issue so we can try to help you.


Well, it happens in case of ajax request. If I call the second URL with ajax, then the first handler also called.


@romain.lanz Hey I was completely wrong in the last comment. Routes are working fine.