Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shy-eels-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-router/dev": patch
---

use only in directory routes on +routes RouteModules
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
- ericschn
- esadek
- faergeek
- fernandojbf
- FilipJirsak
- focusotter
- foxscotch
Expand Down
25 changes: 25 additions & 0 deletions integration/typegen-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,31 @@ test.describe("typegen", () => {
await $("pnpm typecheck");
});

test("route files with paths outside of app directory", async ({
cwd,
edit,
$,
}) => {
await fs.mkdir(Path.join(cwd, "node_modules/external_dependency"), {
recursive: true,
});
await edit({
"app/routes.ts": tsx`
import { type RouteConfig, route } from "@react-router/dev/routes";

export default [
route("outside/:id", "../node_modules/external_dependency/index.js"),
] satisfies RouteConfig;
`,
"node_modules/external_dependency/index.js": tsx`
export default function Component() {
return <div>External Dependency</div>
}
`,
});
await $("pnpm typecheck");
});

test("href", async ({ edit, $ }) => {
await edit({
"app/routes.ts": tsx`
Expand Down
16 changes: 9 additions & 7 deletions packages/react-router-dev/typegen/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,15 @@ function routeModulesType(ctx: Context) {
t.tsPropertySignature(
t.stringLiteral(route.id),
t.tsTypeAnnotation(
t.tsTypeQuery(
t.tsImportType(
t.stringLiteral(
`./${Path.relative(ctx.rootDirectory, ctx.config.appDirectory)}/${route.file}`,
),
),
),
isInAppDirectory(ctx, route.file)
? t.tsTypeQuery(
t.tsImportType(
t.stringLiteral(
`./${Path.relative(ctx.rootDirectory, ctx.config.appDirectory)}/${route.file}`,
),
),
)
: t.tsUnknownKeyword(),
Comment on lines +208 to +216

Choose a reason for hiding this comment

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

You might need to add a test to ensure this works properly, don't conflict with anything else and is not removed in the future

Copy link
Author

@fernandojbf fernandojbf Oct 13, 2025

Choose a reason for hiding this comment

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

Yes, i did not had time to add it, but i will add it now :)
Thanks

Copy link
Author

Choose a reason for hiding this comment

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

Integration test added

),
),
),
Expand Down