diff --git a/src/vite/file.ts b/src/vite/file.ts index a43da0a9..bfd9a476 100644 --- a/src/vite/file.ts +++ b/src/vite/file.ts @@ -18,6 +18,7 @@ export type WriteFileData = { meta: boolean links: boolean } + appDir: string } const defaultGenerationOrder: Exclude[] = [ "links", @@ -32,7 +33,7 @@ const defaultGenerationOrder: Exclude[] = [ "errorBoundary", "revalidate", ] -export const handleWriteFile = async ({ path, options, openInEditor }: WriteFileData) => { +export const handleWriteFile = async ({ path, options, openInEditor, appDir }: WriteFileData) => { const generatorOptions = Object.entries(options) .map(([key, value]) => { if (value) { @@ -40,7 +41,7 @@ export const handleWriteFile = async ({ path, options, openInEditor }: WriteFile } }) .filter(Boolean) as unknown as { key: Exclude }[] - let outputFile = `${resolve("app", "routes", path)}` + let outputFile = `${resolve(appDir, "routes", path)}` const extensions = [".tsx", ".jsx", ".ts", ".js"] if (!extensions.some((ext) => outputFile.endsWith(ext))) { outputFile = `${outputFile}.tsx` diff --git a/src/vite/plugin.tsx b/src/vite/plugin.tsx index 57a865ab..eeae60a5 100644 --- a/src/vite/plugin.tsx +++ b/src/vite/plugin.tsx @@ -106,7 +106,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = ( try { const path = await import("node:path") // Set the route config - const routeConfigExport = (await runner.executeFile(path.join(process.cwd(), "./app/routes.ts"))).default + const routeConfigExport = (await runner.executeFile(path.join(process.cwd(), appDir, "routes.ts"))).default const routeConfig = await routeConfigExport routes = routeConfig @@ -338,7 +338,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = ( }) server.hot.on("open-source", (data: OpenSourceData) => handleOpenSource({ data, openInEditor, appDir })) - server.hot.on("add-route", (data: WriteFileData) => handleWriteFile({ ...data, openInEditor })) + server.hot.on("add-route", (data: WriteFileData) => handleWriteFile({ ...data, openInEditor, appDir })) } }, },