'action' => function ( $year, $month, $all ) {
if ( $page = page($year . '/' . $month . '/' . $all) ) {
return $page->render( [], 'application/json' );
}
}
Note that you needuse a second route that works the other way round and finds the page in the folders.