Skip to content

Commit ecf701e

Browse files
committed
fix: respect custom appDir for route config
1 parent 142df31 commit ecf701e

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/vite/file.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type WriteFileData = {
1818
meta: boolean
1919
links: boolean
2020
}
21+
appDir: string
2122
}
2223
const defaultGenerationOrder: Exclude<Generator, "dependencies">[] = [
2324
"links",
@@ -32,15 +33,15 @@ const defaultGenerationOrder: Exclude<Generator, "dependencies">[] = [
3233
"errorBoundary",
3334
"revalidate",
3435
]
35-
export const handleWriteFile = async ({ path, options, openInEditor }: WriteFileData) => {
36+
export const handleWriteFile = async ({ path, options, openInEditor, appDir }: WriteFileData) => {
3637
const generatorOptions = Object.entries(options)
3738
.map(([key, value]) => {
3839
if (value) {
3940
return { key }
4041
}
4142
})
4243
.filter(Boolean) as unknown as { key: Exclude<Generator, "dependencies"> }[]
43-
let outputFile = `${resolve("app", "routes", path)}`
44+
let outputFile = `${resolve(appDir, "routes", path)}`
4445
const extensions = [".tsx", ".jsx", ".ts", ".js"]
4546
if (!extensions.some((ext) => outputFile.endsWith(ext))) {
4647
outputFile = `${outputFile}.tsx`

src/vite/plugin.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
106106
try {
107107
const path = await import("node:path")
108108
// Set the route config
109-
const routeConfigExport = (await runner.executeFile(path.join(process.cwd(), "./app/routes.ts"))).default
109+
const routeConfigExport = (await runner.executeFile(path.join(process.cwd(), appDir, "routes.ts"))).default
110110
const routeConfig = await routeConfigExport
111111
routes = routeConfig
112112

@@ -338,7 +338,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
338338
})
339339

340340
server.hot.on("open-source", (data: OpenSourceData) => handleOpenSource({ data, openInEditor, appDir }))
341-
server.hot.on("add-route", (data: WriteFileData) => handleWriteFile({ ...data, openInEditor }))
341+
server.hot.on("add-route", (data: WriteFileData) => handleWriteFile({ ...data, openInEditor, appDir }))
342342
}
343343
},
344344
},

0 commit comments

Comments
 (0)