Skip to content
Merged
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: 3 additions & 2 deletions src/vite/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type WriteFileData = {
meta: boolean
links: boolean
}
appDir: string
}
const defaultGenerationOrder: Exclude<Generator, "dependencies">[] = [
"links",
Expand All @@ -32,15 +33,15 @@ const defaultGenerationOrder: Exclude<Generator, "dependencies">[] = [
"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) {
return { key }
}
})
.filter(Boolean) as unknown as { key: Exclude<Generator, "dependencies"> }[]
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`
Expand Down
4 changes: 2 additions & 2 deletions src/vite/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 }))
}
},
},
Expand Down
Loading