Skip to content

fix(route): match page routes case-insensitively like React Router - #7599

Open
RaphaelFakhri wants to merge 1 commit into
reflex-dev:mainfrom
RaphaelFakhri:fix/route-case-insensitive
Open

RaphaelFakhri wants to merge 1 commit into
reflex-dev:mainfrom
RaphaelFakhri:fix/route-case-insensitive

Conversation

@RaphaelFakhri

@RaphaelFakhri RaphaelFakhri commented Oct 19, 2026 •

Copy link
Copy Markdown

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Description

React Router matches route paths case-insensitively by default, so /About renders the page registered at /about. The backend router in reflex/route.py compiled its route regexes case-sensitively and returned no route for that URL. As a result, the page's on_load events did not run, router.page.path was /404, and the production static server answered the SPA fallback with a 404 status.

This change compiles the route regexes with re.IGNORECASE, matching the frontend. Route names are restricted to ASCII letters, digits, _ and -, so the flag has no Unicode side effects.

Testing

  • New test_get_router_ignores_case in tests/units/test_route.py fails on main (4 failed) and passes with the change.
  • uv run pytest tests/units --ignore=tests/units/reflex_cli: 12201 passed, 67 skipped.
  • uv run ruff check, uv run ruff format --check and uv run pyright are clean on the changed files.

Closes #7598

View guided diff

React Router matches route paths case-insensitively by default, so /About renders the about page. The backend router matched case-sensitively, so on_load events and router.page.path fell back to the 404 page for that URL.
@RaphaelFakhri
RaphaelFakhri requested a review from a team as a code owner October 19, 2026 08:20
@greptile-apps

greptile-apps Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Makes backend page routes match without regard to letter case.

  • Backend page routes match URLs regardless of letter case.

Reviews (1) · Last reviewed commit: "fix(route): match page routes case-insen..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="reflex/route.py">

<violation number="1" location="reflex/route.py:184">
P2: `re.IGNORECASE` enables Unicode case folding, so an ASCII route such as `/i` also matches `/İ` and `/ı` (and `/s` matches `/ſ`). Compile with ASCII-restricted case folding to avoid routing Unicode URLs that React Router treats as unmatched.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread reflex/route.py
regex_pattern = f"^{regex_pattern}/?$"
return re.compile(regex_pattern)
# React Router matches route paths case-insensitively by default.
return re.compile(regex_pattern, re.IGNORECASE)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: re.IGNORECASE enables Unicode case folding, so an ASCII route such as /i also matches /İ and /ı (and /s matches /ſ). Compile with ASCII-restricted case folding to avoid routing Unicode URLs that React Router treats as unmatched.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At reflex/route.py, line 184:

<comment>`re.IGNORECASE` enables Unicode case folding, so an ASCII route such as `/i` also matches `/İ` and `/ı` (and `/s` matches `/ſ`). Compile with ASCII-restricted case folding to avoid routing Unicode URLs that React Router treats as unmatched.</comment>

<file context>
@@ -180,7 +180,8 @@ def get_route_regex(keyworded_route: str) -> re.Pattern:
     regex_pattern = f"^{regex_pattern}/?$"
-    return re.compile(regex_pattern)
+    # React Router matches route paths case-insensitively by default.
+    return re.compile(regex_pattern, re.IGNORECASE)
 
 
</file context>
Suggested change
return re.compile(regex_pattern, re.IGNORECASE)
return re.compile(regex_pattern, re.IGNORECASE | re.ASCII)

@masenf masenf added the bug Something isn't working label Oct 19, 2026 — with ChatGPT Codex Connector

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Page routes that differ only in letter case skip on_load and report the 404 route

2 participants