From 60a0d0b34f9c80846ad40ab82e40fde7ab967958 Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Fri, 16 Feb 2024 10:10:05 +0900 Subject: [PATCH] fix: support more than one path params (#61) --- src/utils/file.ts | 2 +- test/unit/utils/file.test.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/file.ts b/src/utils/file.ts index 77a56d0..c387eee 100644 --- a/src/utils/file.ts +++ b/src/utils/file.ts @@ -5,7 +5,7 @@ export const filePathToPath = (filePath: string) => { .replace(/^\/?index$/, '/') // `/index` .replace(/\/index$/, '') // `/about/index` .replace(/\[\.{3}.+\]/, '*') - .replace(/\[(.+)\]/, ':$1') + .replace(/\[(.+?)\]/g, ':$1') return /^\//.test(filePath) ? filePath : '/' + filePath } diff --git a/test/unit/utils/file.test.ts b/test/unit/utils/file.test.ts index df03fab..2b56015 100644 --- a/test/unit/utils/file.test.ts +++ b/test/unit/utils/file.test.ts @@ -27,6 +27,7 @@ describe('filePathToPath', () => { expect(filePathToPath('/about/[name].tsx')).toBe('/about/:name') expect(filePathToPath('/about/[...foo].tsx')).toBe('/about/*') expect(filePathToPath('/about/[name]/address.tsx')).toBe('/about/:name/address') + expect(filePathToPath('/about/[arg1]/[arg2]')).toBe('/about/:arg1/:arg2') }) })