reflex-dev/reflex · error · ValueError

Arg name `{arg_name}` is used more than once in the route `{

Error message

Arg name `{arg_name}` is used more than once in the route `{route}`.

What it means

Route args become keyword arguments passed to the page's state, so each dynamic segment name must be unique. get_route_args raises ValueError when the same arg name (e.g. [id] twice) appears in one route, including mixed required/optional uses like '/[id]/[[id]]'.

Source

Thrown at reflex/route.py:73


def get_route_args(route: str) -> dict[str, str]:
    """Get the dynamic arguments for the given route.

    Args:
        route: The route to get the arguments for.

    Returns:
        The route arguments.
    """
    args = {}

    def _add_route_arg(arg_name: str, type_: str):
        if arg_name in args:
            msg = (
                f"Arg name `{arg_name}` is used more than once in the route `{route}`."
            )
            raise ValueError(msg)
        args[arg_name] = type_

    # Regex to check for route args.
    argument_regex = constants.RouteRegex.ARG
    optional_argument_regex = constants.RouteRegex.OPTIONAL_ARG

    # Iterate over the route parts and check for route args.
    for part in route.split("/"):
        if part == constants.RouteRegex.SPLAT_CATCHALL:
            _add_route_arg("splat", constants.RouteArgType.LIST)
            break

        optional_argument = optional_argument_regex.match(part)
        if optional_argument:
            _add_route_arg(optional_argument.group(1), constants.RouteArgType.SINGLE)
            continue

        argument = argument_regex.match(part)

View on GitHub (pinned to 45b8ed5ab7)

Solutions

  1. Rename one of the duplicates to be specific, e.g. '/[user_id]/items/[item_id]'
  2. For parent/child relationships use prefixed names (user_id, item_id)

Example fix

# before
app.add_page(page, route='/[id]/items/[id]')

# after
app.add_page(page, route='/[user_id]/items/[item_id]')
Defensive patterns

Strategy: validation

Validate before calling

import re

def unique_route_args(route: str) -> bool:
    names = re.findall(r'\[+([A-Za-z_][A-Za-z0-9_]*)\]+', route)
    return len(names) == len(set(names))

Prevention

When it happens

Trigger: app.add_page(page, route='/[id]/items/[id]') or '/user/[name]/[[name]]' — duplicate bracketed names within a single route.

Common situations: Building nested detail routes and reusing 'id' at multiple levels; copy-pasting route prefixes that end in the same param name.

Related errors


AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28). Data as JSON: /api/errors/68fe1de90c679f69. Report an issue: GitHub.