Cake 3.9.2 - Dynamic Routing - The action is not defined in Controller

Hi there,
i need to generate content depending on the route using a Slug and “findBySlug”.
So basically the routes for dynamic content will look like
/[a-z0-9-]+

The Route itself invokes the right controller, but tries to call a function equal the Slug
This /test-page will throw an Exception with

The action testPage is not defined in LandingpagesController

My routes setup:

Router::defaultRouteClass('DashedRoute');
Router::prefix('admin', function ($routes) {
    $routes->extensions(['json']);
    $routes->connect('/', ['controller' => 'Orders', 'action' => 'index']);
    $routes->fallbacks('DashedRoute');
});
Router::scope('/', function ($routes) {
    $routes->connect('/', ['controller' => 'Products', 'action' => 'home']);
    $routes->connect('/search', ['controller' => 'Products', 'action' => 'search']);
    // many other routes, some static, some dynamic ones

   // this will result in action not found
   $routes->connect('/:action',
        ['controller' => 'Landingpages', 'action' => 'view'],
    )->setPatterns(['action' => '[a-z0-9-]+'])
        ->setPass(['action']);

   $routes->connect('/*', ['controller' => 'Products', 'action' => 'index']);
   $routes->fallbacks(DashedRoute::class);
});

Reading through the Docs Routing - 3.10 didn’t solved my Problem.
So what i’m doing wrong?

Update: changed setup for DashedRoute to:

Router::defaultRouteClass(DashedRoute::class);
// ...
$routes->fallbacks(DashedRoute::class);

You need to use DashedRoute::class instead of 'DashedRoute' for Router::defaultRouteClass() and $routes->fallbacks('DashedRoute').

I tried that, but issue still exists

I haven’t done much with custom routing, but setPatterns(['action' => '[a-z0-9-]+']) would seem to be setting the action for it to call, rather than a parameter to pass to the view action?

@Zuluru when i put in view as pattern then i get the same error

If i use the controller name in url like this

$routes
        ->connect('/landingpages/:slug',
            ['controller' => 'Landingpages', 'action' => 'view'],
        )
        ->setPatterns(['slug' => '[a-z0-9-]+'])
        ->setPass(['slug']);

then view function is called.

But how to get rid of the controller name in the url?

So you just want a URL like /<slug>? What if the slug is “search” or “admin”, which you already have other routes defined for?

Yes, i need to get rid of.
Using this Route setup still works with other Routes

$routes
        ->connect('/:action',
            ['controller' => 'Landingpages', 'action' => 'view'],
        )
        ->setPatterns(['action' => '[a-z0-9-]+'])
        ->setPass(['action']);