Skip to content

fix: normalize file path before creating route ID in configRoutesToRouteManifest#14952

Open
restareaByWeezy wants to merge 2 commits intoremix-run:devfrom
restareaByWeezy:fix/relative-route-id
Open

fix: normalize file path before creating route ID in configRoutesToRouteManifest#14952
restareaByWeezy wants to merge 2 commits intoremix-run:devfrom
restareaByWeezy:fix/relative-route-id

Conversation

@restareaByWeezy
Copy link
Copy Markdown

Problem

Fixes #14125

When routes are defined using the relative() helper in routes.ts, route IDs become absolute file paths (e.g., /home/projects/app/routes/home) instead of the expected relative paths (e.g., routes/home).

This happens because relative() calls Path.resolve(directory, file) to produce absolute paths, and configRoutesToRouteManifest passes this absolute path directly to createRouteId() without normalizing it first.

Root Cause

In configRoutesToRouteManifest's walk() function, the file property was already normalized from absolute to relative:

file: Path.isAbsolute(route.file)
  ? Path.relative(appDirectory, route.file)
  : route.file,

But createRouteId(route.file) on the line above used the raw route.file, which is still absolute when coming from relative().

Solution

Extract the file normalization into a shared normalizedFile variable so both the route ID and the file property use the relative path.

let normalizedFile = Path.isAbsolute(route.file)
  ? Path.relative(appDirectory, route.file)
  : route.file;
let id = route.id || createRouteId(normalizedFile);

This is a minimal change that applies the existing normalization logic to the ID computation.

Changeset

Included a patch changeset for @react-router/dev.

Test Plan

  • Verified the logic: relative() produces absolute paths via Path.resolve(), and the fix ensures createRouteId receives a relative path, matching the behavior of non-relative() routes
  • No existing unit tests for configRoutesToRouteManifest in the repo; the fix is a straightforward refactor of existing normalization logic

…uteManifest

When routes are defined using the relative() helper, route.file is an
absolute path (via Path.resolve). The file property was already
normalized to a relative path, but createRouteId used the raw
route.file, producing absolute route IDs like
"/home/user/app/routes/home" instead of "routes/home".

Extract the normalization into a shared variable so both the ID and
file property use the relative path.

Fixes remix-run#14125
@remix-cla-bot
Copy link
Copy Markdown
Contributor

remix-cla-bot Bot commented Apr 7, 2026

Hi @restareaByWeezy,

Welcome, and thank you for contributing to React Router!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run.

Thanks!

- The Remix team

@remix-cla-bot
Copy link
Copy Markdown
Contributor

remix-cla-bot Bot commented Apr 7, 2026

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

@github-actions
Copy link
Copy Markdown
Contributor

👋 We've moved away from Changesets to our own internal changes process. Please convert your changesets file to a change file in the proper package directory (i.e., packages/react-router/.changes/patch.fix-some-bug.md).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants