From 7e8be92cd5959c060b4a799752407185f034b7c0 Mon Sep 17 00:00:00 2001 From: Valerio Ageno Date: Sat, 4 Jan 2025 10:33:17 +0100 Subject: [PATCH] fix: catch-all server side handler --- .../src/generator.ts | 22 +++++++++---------- .../generator/catch_all/routeTree.expected.ts | 1 + .../catch_all/routes/posts/[...catch_all].rs | 0 3 files changed, 11 insertions(+), 12 deletions(-) create mode 100644 packages/tuono-fs-router-vite-plugin/tests/generator/catch_all/routes/posts/[...catch_all].rs diff --git a/packages/tuono-fs-router-vite-plugin/src/generator.ts b/packages/tuono-fs-router-vite-plugin/src/generator.ts index 657d90f6..0d71622e 100644 --- a/packages/tuono-fs-router-vite-plugin/src/generator.ts +++ b/packages/tuono-fs-router-vite-plugin/src/generator.ts @@ -85,8 +85,7 @@ async function getRouteNodes( } else if (fullPath.match(/\.(rs)$/)) { const filePath = replaceBackslash(path.join(dir, dirent.name)) const filePathNoExt = removeExt(filePath) - let routePath = - cleanPath(`/${filePathNoExt.split('.').join('/')}`) || '' + let routePath = cleanPath(`/${filePathNoExt}`) || '' if (routePath === 'index') { routePath = '/' @@ -167,17 +166,16 @@ export async function routeGenerator(config = defaultConfig): Promise { const imports = [ ...sortedRouteNodes.map((node) => { const extension = node.filePath.endsWith('mdx') ? '.mdx' : '' - return `const ${ - node.variableName as string - }Import = dynamic(() => import('./${replaceBackslash( - removeExt( - path.relative( - path.dirname(config.generatedRouteTree), - path.resolve(config.folderName, node.filePath), + return `const ${node.variableName as string + }Import = dynamic(() => import('./${replaceBackslash( + removeExt( + path.relative( + path.dirname(config.generatedRouteTree), + path.resolve(config.folderName, node.filePath), + ), + false, ), - false, - ), - )}${extension}'))` + )}${extension}'))` }), ].join('\n') diff --git a/packages/tuono-fs-router-vite-plugin/tests/generator/catch_all/routeTree.expected.ts b/packages/tuono-fs-router-vite-plugin/tests/generator/catch_all/routeTree.expected.ts index a50af4c9..7910bdd7 100644 --- a/packages/tuono-fs-router-vite-plugin/tests/generator/catch_all/routeTree.expected.ts +++ b/packages/tuono-fs-router-vite-plugin/tests/generator/catch_all/routeTree.expected.ts @@ -24,6 +24,7 @@ const IndexRoute = Index.update({ const PostscatchallRoute = Postscatchall.update({ path: '/posts/[...catch_all]', getParentRoute: () => rootRoute, + hasHandler: true, }) // Create and export the route tree diff --git a/packages/tuono-fs-router-vite-plugin/tests/generator/catch_all/routes/posts/[...catch_all].rs b/packages/tuono-fs-router-vite-plugin/tests/generator/catch_all/routes/posts/[...catch_all].rs new file mode 100644 index 00000000..e69de29b