Skip to content

[spiral/router] Group's prefix is not applied to routes #1217

@Lisio

Description

@Lisio

When using a route group with prefix defined as "/console" the routes attached to this group still must contain it.

protected function configureRouteGroups(GroupRegistry $groups): void
{
    $groups->getGroup('console:user')
        ->setNamePrefix('/console')
        ->setPrefix('/console');
}

protected function defineRoutes(RoutingConfigurator $routes): void
{
    $consoleUserRoutes = [
        // ...
        '/project/search' => [ProjectController::class, 'search'],
        // ...
    ];
    foreach ($consoleUserRoutes as $path => $target) {
        $routes->add($path, $path)
            ->group('console:user')
            ->methods('POST')
            ->action($target[0], $target[1]);
    }
}

The code above doesn't work and I have to do this:

$consoleUserRoutes = [
    // ...
    '/console/project/search' => [ProjectController::class, 'search'],
    // ...
];

or this:

$routes->add($path, $path)
    ->prefix('/console')
    ->group('console:user')
    ->methods('POST')
    ->action($target[0], $target[1]);

Spiral Framework version: 3.15.3

Metadata

Metadata

Assignees

Type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions