Skip to content

Commit 8fd0b0b

Browse files
fix: resolve route file outside of app dir relative to app dir
1 parent 70dba29 commit 8fd0b0b

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

.changeset/red-pugs-itch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-router/fs-routes": patch
3+
---
4+
5+
Resolve route file outside of app directory relative to app directory

packages/react-router-fs-routes/__tests__/flatRoutes-test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,4 +912,14 @@ describe("flatRoutes", () => {
912912
);
913913
});
914914
});
915+
916+
test("should include a valid file for a route outside of the app directory", () => {
917+
const routesDir = path.join("test", "root", "routes");
918+
const routeFile = path.join(routesDir, "route.tsx");
919+
920+
const manifest = flatRoutesUniversal(APP_DIR, [routeFile]);
921+
const routeInfo = manifest[path.relative(APP_DIR, routesDir)];
922+
expect(routeInfo).toBeDefined();
923+
expect(routeInfo.file).toBe(path.relative(APP_DIR, routeFile));
924+
});
915925
});

packages/react-router-fs-routes/flatRoutes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export function flatRoutesUniversal(
174174
let pathname = createRoutePath(segments, raw, index);
175175

176176
routeManifest[routeId] = {
177-
file: file.slice(appDirectory.length + 1),
177+
file: path.relative(appDirectory, file),
178178
id: routeId,
179179
path: pathname,
180180
};

0 commit comments

Comments
 (0)