Custom routes return 404 error but correct content with HEAD request

I can’t reproduce this at all, my example code is in the other topic.

Maybe what you are missing is actually printing the $response? Because that line is missing in all of your examples. But it is required as the router itself only does the routing, it does not do the response handling. It just returns the return value of the route.

I also can’t reproduce the “404 error when returning a response object from a c::set('routes') route” issue. Can you maybe post a reduced test case that I can reproduce directly in the starterkit?

Please note that the custom routers are only supposed to be used inside plugins. If you plan to use site-specific routes inside the site’s config.php, it is better to use the c::set('routes') option to avoid having to spin up two routers.