{"record":{"id":"954429d625d415f1","repo":"reflex-dev/reflex","slug":"route-part-part-with-argument-is-not-valid-re","errorCode":null,"errorMessage":"Route part `{part}` with argument is not valid. Reflex only supports argument names that start with an alphabetic character or underscore, followed by alphanumeric characters or underscores.","messagePattern":"Route part `(.+?)` with argument is not valid\\. Reflex only supports argument names that start with an alphabetic character or underscore, followed by alphanumeric characters or underscores\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"reflex/route.py","lineNumber":54,"sourceCode":"                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):\n            msg = (\n                f\"Route part `{part}` with argument is not valid. \"\n                \"Reflex only supports argument names that start with an alphabetic character or underscore, \"\n                \"followed by alphanumeric characters or underscores.\"\n            )\n            raise ValueError(msg)\n\n\ndef get_route_args(route: str) -> dict[str, str]:\n    \"\"\"Get the dynamic arguments for the given route.\n\n    Args:\n        route: The route to get the arguments for.\n\n    Returns:\n        The route arguments.\n    \"\"\"\n    args = {}\n\n    def _add_route_arg(arg_name: str, type_: str):\n        if arg_name in args:\n            msg = (\n                f\"Arg name `{arg_name}` is used more than once in the route `{route}`.\"\n            )","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/reflex/route.py#L36-L72","documentation":"Required dynamic route segments ([arg]) must match RouteRegex.ARG: a name starting with a letter or underscore followed by alphanumerics/underscores. Segments like [1id], [my-arg], or [] are rejected by verify_route_validity when the page is added.","triggerScenarios":"app.add_page(page, route='/user/[user-id]') or '/post/[1id]' — invalid identifier characters inside single brackets.","commonSituations":"Translating kebab-case URL slugs into route params; using numeric IDs as param names; typos leaving empty brackets [].","solutions":["Use a valid Python-style identifier: [user_id] or [id]","Avoid hyphens, digits at the start, and empty brackets","Remember the arg name maps to a state var annotation, so it must be a valid identifier"],"exampleFix":"# before\napp.add_page(page, route='/user/[user-id]')\n\n# after\napp.add_page(page, route='/user/[user_id]')","handlingStrategy":"validation","validationCode":"import re\nARG = re.compile(r'\\[[A-Za-z_][A-Za-z0-9_]*\\]')\n\ndef valid_arg(part: str) -> bool:\n    return bool(ARG.fullmatch(part))","typeGuard":"def is_valid_route_part(part: str) -> bool:\n    import re\n    return bool(re.fullmatch(r'\\[[A-Za-z_][A-Za-z0-9_]*\\]', part))","tryCatchPattern":null,"preventionTips":["Keep arg names valid Python identifiers since they map to state var annotations","Lint routes in CI with a regex test"],"tags":["reflex","routing","dynamic-routes","validation"],"backgroundTag":"route-pattern-validation-failed","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}