Skip to content

fix: sort programmatic routes by specificity to prevent shadowing#3865

Open
SisyphusZheng wants to merge 3 commits into
freshframework:mainfrom
SisyphusZheng:fix/route-specificity-sorting
Open

fix: sort programmatic routes by specificity to prevent shadowing#3865
SisyphusZheng wants to merge 3 commits into
freshframework:mainfrom
SisyphusZheng:fix/route-specificity-sorting

Conversation

@SisyphusZheng

Copy link
Copy Markdown
Contributor

Routes registered via app.route() / app.get() are matched in registration order (first-wins). File-system routes go through sortRoutePaths() which orders by specificity, but programmatic routes bypass this entirely. This means registering a catch-all before a specific route silently shadows it:

app.route("/blog/[...rest]", handlerA);  // catches everything
app.route("/blog/[id]", handlerB);        // NEVER reached

This PR sorts #dynamicArr whenever a new dynamic route is added, using the same specificity scoring as sortRoutePaths: static segments > dynamic [id] > catch-all [...rest].

Closes #3861

A previous commit accidentally changed \import prefresh from\ to \import { prefresh } from\ and modified regex escaping in the exclude array. Revert both files to match main.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Programmatic routes via app.route() bypass specificity sorting

1 participant