{"record":{"id":"3d34e269d260d2f6","repo":"reflex-dev/reflex","slug":"route-part-part-is-not-valid-reflex-only-supp","errorCode":null,"errorMessage":"Route part `{part}` is not valid. Reflex only supports alphabetic characters, underscores, and hyphens in route parts. ","messagePattern":"Route part `(.+?)` is not valid\\. Reflex only supports alphabetic characters, underscores, and hyphens in route parts\\. ","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"reflex/route.py","lineNumber":30,"sourceCode":"def verify_route_validity(route: str) -> None:\n    \"\"\"Verify if the route is valid, and throw an error if not.\n\n    Args:\n        route: The route that need to be checked\n\n    Raises:\n        ValueError: If the route is invalid.\n    \"\"\"\n    route_parts = route.removeprefix(\"/\").split(\"/\")\n    for i, part in enumerate(route_parts):\n        if constants.RouteRegex.SLUG.fullmatch(part):\n            continue\n        if not part.startswith(\"[\") or not part.endswith(\"]\"):\n            msg = (\n                f\"Route part `{part}` is not valid. Reflex only supports \"\n                \"alphabetic characters, underscores, and hyphens in route parts. \"\n            )\n            raise ValueError(msg)\n        if part.startswith((\"[[...\", \"[...\")):\n            if part != constants.RouteRegex.SPLAT_CATCHALL:\n                msg = f\"Catchall pattern `{part}` is not valid. Only `{constants.RouteRegex.SPLAT_CATCHALL}` is allowed.\"\n                raise ValueError(msg)\n            if i != len(route_parts) - 1:\n                msg = f\"Catchall pattern `{part}` must be at the end of the route.\"\n                raise ValueError(msg)\n            continue\n        if part.startswith(\"[[\"):\n            if constants.RouteRegex.OPTIONAL_ARG.fullmatch(part):\n                continue\n            msg = (\n                f\"Route part `{part}` with optional argument is not valid. \"\n                \"Reflex only supports optional arguments that start with an alphabetic character or underscore, \"\n                \"followed by alphanumeric characters or underscores.\"\n            )\n            raise ValueError(msg)\n        if not constants.RouteRegex.ARG.fullmatch(part):","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/reflex/route.py#L12-L48","documentation":"Reflex validates dynamic route segments; any part wrapped in brackets that is not an accepted pattern is rejected. A part starting with '[' but not ending with ']', or malformed bracket usage, triggers this message, which lists the allowed characters (alphabetic, underscores, hyphens) for static parts. Raised from reflex.route.verify_route_validity, called when adding a page via app.add_page.","triggerScenarios":"Calling app.add_page(component, route='/user/[id') with an unclosed bracket, or route='/[123]' style segments that fail later regex checks, or a static segment containing invalid characters that got wrapped in brackets.","commonSituations":"Migrating Next.js/Flask style routes ('/user/<id>', '/user/:id') to Reflex's bracket syntax; typos in dynamic route definitions; leftover brackets in generated route strings.","solutions":["Use bracket syntax for dynamic args: /user/[id]","For optional args use double brackets: /user/[[id]]","For static parts use only letters, underscores, hyphens — no brackets","For catchall use exactly /[[...slug]] at the end of the route"],"exampleFix":"# before\napp.add_page(index, route='/user/<id>')\n\n# after\napp.add_page(index, route='/user/[id]')","handlingStrategy":"validation","validationCode":"import re\nfrom reflex.route import verify_route_validity\n\ndef safe_add_page(app, component, route):\n    verify_route_validity(route)\n    app.add_page(component, route=route)","typeGuard":null,"tryCatchPattern":"try:\n    app.add_page(page, route=route)\nexcept ValueError as e:\n    raise SystemExit(f'Invalid route {route!r}: {e}') from e","preventionTips":["Use bracket syntax [id], [[optional]], [[...slug]] consistently","Run verify_route_validity in a unit test over all registered routes"],"tags":["reflex","routing","routes","validation","add-page"],"backgroundTag":"route-pattern-validation-failed","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}