{"record":{"id":"2cdf9c05a4421525","repo":"phalcon/cphalcon","slug":"the-group-of-routes-does-not-contain-any-routes","errorCode":null,"errorMessage":"The group of routes does not contain any routes","messagePattern":"The group of routes does not contain any routes","errorType":"exception","errorClass":"Phalcon\\Mvc\\Router\\Exceptions\\EmptyGroupOfRoutes","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Router.zep","lineNumber":1818,"sourceCode":"     *\n     * @param GroupInterface group\n     *\n     * @return static\n     */\n    public function mount(<GroupInterface> group) -> <static>\n    {\n        var groupRoutes, beforeMatch, hostname, route, eventsManager;\n\n        let eventsManager = this->eventsManager;\n\n        if typeof eventsManager == \"object\" {\n            eventsManager->fire(\"router:beforeMount\", this, group);\n        }\n\n        let groupRoutes = group->getRoutes();\n\n        if unlikely empty groupRoutes {\n            throw new EmptyGroupOfRoutes();\n        }\n\n        /**\n         * Get the before-match condition\n         */\n        let beforeMatch = group->getBeforeMatch();\n\n        if beforeMatch !== null {\n            for route in groupRoutes {\n                route->beforeMatch(beforeMatch);\n            }\n        }\n\n        // Get the hostname restriction\n        let hostname = group->getHostName();\n\n        if hostname !== null {\n            for route in groupRoutes {","sourceCodeStart":1800,"sourceCodeEnd":1836,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Router.zep#L1800-L1836","documentation":"Router::mount() requires a RouteGroupInterface that actually contains routes: it fires router:beforeMount, fetches group->getRoutes(), and if the collection is empty throws EmptyGroupOfRoutes. An empty group would silently register nothing, so the router treats it as a configuration mistake. A prefix, hostname, or beforeMatch alone does not count as content.","triggerScenarios":"$router->mount((new Group())->setPrefix('/admin')) where no $group->add(...) was called before mount; calling mount() before a conditional block that adds routes; a group whose routes are attached to a different instance (e.g. you built routes on a cloned/copied group).","commonSituations":"Refactoring route registration into group classes and forgetting the load() / add() calls; conditionally skipping route additions (feature flag off) while still mounting the shell group; mount ordered before route definitions in a bootstrap script.","solutions":["Add at least one route to the group before mounting: $group->add('/dashboard', ['controller' => 'dashboard', 'action' => 'index']); then $router->mount($group);","If the group may legitimately be empty (dynamic modules), guard the mount: if (count($group->getRoutes()) > 0) { $router->mount($group); }","Check that you mounted the same group instance you populated, not a fresh copy"],"exampleFix":"// before\n$group = (new Group())->setPrefix('/admin');\n$router->mount($group); // no routes added yet\n\n// after\n$group = (new Group())->setPrefix('/admin');\n$group->add(\n    '/dashboard',\n    ['controller' => 'dashboard', 'action' => 'index']\n);\n$router->mount($group);","handlingStrategy":"validation","validationCode":"// only mount groups that actually contain routes\n$group = new \\Phalcon\\Mvc\\Router\\Group('/admin');\n// ... conditional route additions ...\n\nif (count($group->getRoutes()) > 0) {\n    $router->mount($group);\n} else {\n    $logger->warning('Skipped mounting empty group /admin');\n}","typeGuard":"function isMountableGroup(\\Phalcon\\Mvc\\Router\\RouteGroupInterface $group): bool\n{\n    return count($group->getRoutes()) > 0;\n}","tryCatchPattern":"try {\n    $router->mount($group);\n} catch (\\Phalcon\\Mvc\\Router\\Exceptions\\EmptyGroupOfRoutes $e) {\n    // treat as a build error: a route group lost all its definitions\n    $logger->error('Refused to mount empty group: ' . $e->getMessage());\n    throw $e;\n}","preventionTips":["Always add() at least one route to a group before mount() in the same code block","When feature flags conditionally remove routes, guard the mount with a count check","Unit-test each group class returns a non-empty getRoutes()"],"tags":["phalcon","router","groups","mount","validation"],"backgroundTag":"empty-route-group","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}