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

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::prefix('admin', function ($routes) {
    $routes->connect('/', ['controller' => 'Orders', 'action' => 'index']);
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
        ['controller' => 'Landingpages', 'action' => 'view'],
    )->setPatterns(['action' => '[a-z0-9-]+'])

   $routes->connect('/*', ['controller' => 'Products', 'action' => 'index']);

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

Update: changed setup for DashedRoute to:

// ...

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

            ['controller' => 'Landingpages', 'action' => 'view'],
        ->setPatterns(['slug' => '[a-z0-9-]+'])

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

            ['controller' => 'Landingpages', 'action' => 'view'],
        ->setPatterns(['action' => '[a-z0-9-]+'])