Custom routes return 404 error but correct content with HEAD request

Just like in a custom router, either by name of a function or via an anonymous function:

c:set( 'routes', array(
	array(
		'pattern' => 'archive/(:num)/mail',
		'method' => 'ALL',
        'filter' => function($route) {
           // some checks
          // $route is the route array
         },
		'action' => function( $no ) {
			if ( $issue = page( 'archive/' . $no ) ) {
				return new Response(
					snippet( 'copyMail', array( 'issue' => $issue ), true )
				);
			}
		}
	),
) );
1 Like

The example by @texnixe should work, but a small addition: Name of a function does not work, it actually needs to be a PHP Closure object (anonymous function).

“Global filters” by name are not supported for the Kirby built-in router as there is no way to register global filters in the Kirby router. That’s only possible in custom routers. But of course you can use Closures instead, they work everywhere. :slight_smile:

2 Likes