{"record":{"id":"1382eee3b42a3ef6","repo":"cakephp/cakephp","slug":"cannot-find-route-class-s","errorCode":null,"errorMessage":"Cannot find route class %s","messagePattern":"Cannot find route class (.+?)","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Routing/RouteBuilder.php","lineNumber":761,"sourceCode":"    }\n\n    /**\n     * Create a route object, or return the provided object.\n     *\n     * @param \\Cake\\Routing\\Route\\Route|string $route The route template or route object.\n     * @param array $defaults Default parameters.\n     * @param array<string, mixed> $options Additional options parameters.\n     * @return \\Cake\\Routing\\Route\\Route\n     * @throws \\InvalidArgumentException when route class or route object is invalid.\n     * @throws \\BadMethodCallException when the route to make conflicts with the current scope\n     */\n    protected function _makeRoute(Route|string $route, array $defaults, array $options): Route\n    {\n        if (is_string($route)) {\n            /** @var class-string<\\Cake\\Routing\\Route\\Route>|null $routeClass */\n            $routeClass = App::className($options['routeClass'], 'Routing/Route');\n            if ($routeClass === null) {\n                throw new InvalidArgumentException(sprintf(\n                    'Cannot find route class %s',\n                    $options['routeClass'],\n                ));\n            }\n\n            $route = str_replace('//', '/', $this->_path . $route);\n            if ($route !== '/') {\n                $route = rtrim($route, '/');\n            }\n\n            foreach ($this->_params as $param => $val) {\n                if (isset($defaults[$param]) && $param !== 'prefix' && $defaults[$param] !== $val) {\n                    $msg = 'You cannot define routes that conflict with the scope. ' .\n                        'Scope had %s = %s, while route had %s = %s';\n                    throw new BadMethodCallException(sprintf(\n                        $msg,\n                        $param,\n                        $val,","sourceCodeStart":743,"sourceCodeEnd":779,"githubUrl":"https://github.com/cakephp/cakephp/blob/1128eba9b09f1946df684811350e26f2cef68fac/src/Routing/RouteBuilder.php#L743-L779","documentation":"RouteBuilder::_makeRoute() accepts a route class name string and resolves it with App::className() in the Routing/Route namespace. If the class does not exist (or is not autoloadable), the builder throws this InvalidArgumentException instead of instantiating an unknown class.","triggerScenarios":"connect('/path', [...], ['routeClass' => 'MyRoute']) where src/Routing/Route/MyRoute.php doesn't exist; typo in the routeClass name; forgetting to define the class in the app namespace; a plugin route class that is not loaded.","commonSituations":"Custom route classes after refactors; copying routeClass options from tutorials with nonexistent classes; PSR-4 namespace mismatch so autoloading fails.","solutions":["Create the class at src/Routing/Route/{Name}Route.php extending Cake\\Routing\\Route\\Route.","Correct the routeClass option spelling, e.g. 'routeClass' => 'DashedRoute' (name without the 'Route' suffix).","Verify composer autoload/PSR-4 mapping includes the app namespace.","Remove the routeClass option if the default (or an existing built-in) class suffices."],"exampleFix":"// before\n$routes->connect('/pages/*', ['controller' => 'Pages'], ['routeClass' => 'FancyRoute']);\n// after (class exists or use built-in)\n$routes->connect('/pages/*', ['controller' => 'Pages'], ['routeClass' => 'DashedRoute']);","handlingStrategy":"validation","validationCode":"use Cake\\Core\\App;\nif (App::className('FancyRoute', 'Routing/Route') === null) {\n    throw new RuntimeException('Route class does not exist');\n}","typeGuard":null,"tryCatchPattern":"try {\n    $builder->connect('/path', $defaults, ['routeClass' => $class]);\n} catch (\\InvalidArgumentException $e) {\n    // fall back to default Route class\n}","preventionTips":["Create custom route classes in src/Routing/Route/ matching PSR-4 naming.","Test route definitions in CI so missing classes are caught at build time.","Only use built-in routeClass names (DashedRoute, InflectedRoute) unless the custom class exists."],"tags":["php","cakephp","routing","class-not-found","autoloading"],"backgroundTag":"class-not-found","analyzedSha":"1128eba9b09f1946df684811350e26f2cef68fac","analyzedAt":"2026-09-12T12:07:00.388Z","contentChangedAt":"2026-09-12T12:07:00.388Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}