Skip to content

Commit 838343f

Browse files
committed
fix: use only in directory routes on +routes RouteModules
1 parent 1abe213 commit 838343f

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

.changeset/shy-eels-drum.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-router/dev": patch
3+
---
4+
5+
use only in directory routes on +routes RouteModules

contributors.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
- ericschn
118118
- esadek
119119
- faergeek
120+
- fernandojbf
120121
- FilipJirsak
121122
- focusotter
122123
- foxscotch

integration/typegen-test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,35 @@ test.describe("typegen", () => {
456456
await $("pnpm typecheck");
457457
});
458458

459+
test("route files with paths outside of app directory", async ({
460+
cwd,
461+
edit,
462+
$,
463+
}) => {
464+
await edit({
465+
"app/routes.ts": tsx`
466+
import { type RouteConfig, route } from "@react-router/dev/routes";
467+
468+
export default [
469+
route("outside/:id", "../node_modules/external_dependency/index.js"),
470+
] satisfies RouteConfig;
471+
`,
472+
});
473+
474+
await fs.mkdir(Path.join(cwd, "./node_modules/external_dependency"), {
475+
recursive: true,
476+
});
477+
await fs.writeFile(
478+
Path.join(cwd, "./node_modules/external_dependency/index.js"),
479+
`
480+
export default function Component() {
481+
return <h1>External Dependency</h1>
482+
}
483+
`,
484+
);
485+
await $("pnpm typecheck");
486+
});
487+
459488
test("href", async ({ edit, $ }) => {
460489
await edit({
461490
"app/routes.ts": tsx`

packages/react-router-dev/typegen/generate.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,15 @@ function routeModulesType(ctx: Context) {
205205
t.tsPropertySignature(
206206
t.stringLiteral(route.id),
207207
t.tsTypeAnnotation(
208-
t.tsTypeQuery(
209-
t.tsImportType(
210-
t.stringLiteral(
211-
`./${Path.relative(ctx.rootDirectory, ctx.config.appDirectory)}/${route.file}`,
212-
),
213-
),
214-
),
208+
isInAppDirectory(ctx, route.file)
209+
? t.tsTypeQuery(
210+
t.tsImportType(
211+
t.stringLiteral(
212+
`./${Path.relative(ctx.rootDirectory, ctx.config.appDirectory)}/${route.file}`,
213+
),
214+
),
215+
)
216+
: t.tsUnknownKeyword(),
215217
),
216218
),
217219
),

0 commit comments

Comments
 (0)