Slim 4 get name route

Error: Cannot create RouteContext before routing has been completed
How fix it?

You just need to add your routingMiddleware before the middleware or handler where you are trying to create that routeContext.

From the documentation

The routing middleware should be added earlier than the ErrorMiddleware
Otherwise exceptions thrown from it will not be handled by the middleware

Error Handling Middleware

ok. but don’t work

The Slim middleware is LIFO (last in, first out). Try to add your middleware first.

1 Like

It’s working.
Source code: