cakephp: Duplicate Named Route for plugin

This is a (multiple allowed):

  • bug

  • enhancement

  • feature-discussion (RFC)

  • CakePHP Version: 3.6.4

What you did

load plugin with routes in bootstrap Plugin::load('I18nUrl', ['routes' => true]);

call Plugin::routes() at the end of config/routes.php in base app

create a route in plugin

use Cake\Routing\Router;
use Cake\Routing\RouteBuilder;

Router::plugin('Backend', ['path' => '/gestion'], function (RouteBuilder $routes) {
    $routes->connect('/', ['controller' => 'Dashboard', 'action' => 'index'], ['_name' => 'backend.dashboard']);
});

What happened

Cake\Routing\Exception\DuplicateNamedRouteException Error: A route named "backend.dashboard" has already been connected to "/gestion".

What you expected to happen

no duplicate routes

where to search

It’s look like the RoutingMiddleware now check if $this->app is instance of PluginApplicationInterface

the src/Application extends BaseApplication which implement PluginApplicationInterface SO the standard application build plugin routes twice, first via application and bootstrap, second time via the RoutingMiddleware::prepareRouteCollection()

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (18 by maintainers)

Commits related to this issue

Most upvoted comments

You should remove the Plugin::routes() call in your routes file. It is only necessary if you are using the deprecated Dispatcher classes.