{"record":{"id":"9cebe7fca32d02c9","repo":"reflex-dev/reflex","slug":"route-part-part-with-optional-argument-is-not","errorCode":null,"errorMessage":"Route part `{part}` with optional argument is not valid. Reflex only supports optional arguments that start with an alphabetic character or underscore, followed by alphanumeric characters or underscores.","messagePattern":"Route part `(.+?)` with optional argument is not valid\\. Reflex only supports optional arguments 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":47,"sourceCode":"            )\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):\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    \"\"\"","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/reflex/route.py#L29-L65","documentation":"Optional route arguments use double-bracket syntax ([[arg]]) and must match RouteRegex.OPTIONAL_ARG: start with a letter or underscore followed by alphanumerics/underscores. Segments like [[1id]], [[my-arg]], or [[]] fail validation in verify_route_validity.","triggerScenarios":"app.add_page(page, route='/item/[[123]]') or '/item/[[my-arg]]' — names starting with a digit or containing hyphens/spaces inside double brackets.","commonSituations":"Using hyphenated slug names from URL conventions (my-arg) inside optional brackets; numeric identifiers as optional arg names.","solutions":["Rename the optional arg to a valid identifier: [[my_arg]] or [[id]]","Use single brackets for required args: [id]","Ensure the name starts with a letter or underscore"],"exampleFix":"# before\napp.add_page(page, route='/item/[[my-arg]]')\n\n# after\napp.add_page(page, route='/item/[[my_arg]]')","handlingStrategy":"validation","validationCode":"import re\nOPTIONAL_ARG = re.compile(r'\\[\\[[A-Za-z_][A-Za-z0-9_]*\\]\\]')\n\ndef valid_optional(part: str) -> bool:\n    return bool(OPTIONAL_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":["Use snake_case identifiers inside brackets","Never start an arg name with a digit or use hyphens"],"tags":["reflex","routing","optional-args","validation"],"backgroundTag":"route-pattern-validation-failed","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}