Skip to content

flatRoutes rootDirectory cannot be outside of appDirectory #13063

Open
@meznaric

Description

@meznaric

I'm using React Router as a...

framework

Reproduction

Go to https://stackblitz.com/edit/github-93cysh5j

In terminal run npm run routes or npm run dev.

What did I do in that stack blitz:

  1. I moved root and entry files to subdirectory app/core
  2. I kept routes folder in app/routes
  3. I used flatRoutes package in app/core/routes.ts and pointed it at ../routes

System Info

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 1.36 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.15.0 - ~/.asdf/installs/nodejs/20.15.0/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.7.0 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 10.4.1 - /opt/homebrew/bin/pnpm
    Watchman: 2024.12.02.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 133.0.6943.126
    Safari: 17.5
  npmPackages:
    @react-router/dev: ^7.0.0 => 7.2.0
    @react-router/fs-routes: ^7.1.5 => 7.2.0
    @react-router/node: ^7.0.0 => 7.2.0
    @react-router/serve: ^7.0.0 => 7.2.0
    react-router: ^7.0.0 => 7.2.0
    vite: ^6.1.0 => 6.1.0

Used Package Manager

npm

Expected Behavior

You expect the app to start. And you expect this this file to be loaded:

path: '/home/projects/github-93cysh5j/app/routes/home.tsx'

Actual Behavior

But you actually see this being loaded:

path: '/home/projects/github-93cysh5j/app/core/s/home.tsx'

Notice how route was replaced with core/?

This seems to be result of this line

file: file.slice(appDirectory.length + 1),
which assumes that routes will always be part of the appDirectory, so the replacement happens:

 /home/projects/github-93cysh5j/app/routes/home.tsx
-/home/projects/github-93cysh5j/app/route
+/home/projects/github-93cysh5j/app/core/
=/home/projects/github-93cysh5j/app/core/s/home.tsx

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions