optional splat routes (#13547)

Co-authored-by: SteelRazor47 <36779933+SteelRazor47@users.noreply.github.com>
This commit is contained in:
Leonardo Benini
2025-11-05 17:17:09 +01:00
committed by GitHub
parent 423b6d94dc
commit 1762f73bd9
4 changed files with 35 additions and 9 deletions

View File

@@ -4,7 +4,11 @@ export function getRoute(file: string): string {
const importPath = normalizePath(file)
return importPath
.replace(/.*\/admin\/(routes)/, "")
.replace(/\[([^\]]+)\]/g, ":$1")
.replace("[[*]]", "*?") // optional splat
.replace("[*]", "*") // splat
.replace(/\(([^\[\]\)]+)\)/g, "$1?") // optional static, (foo)
.replace(/\[\[([^\]]+)\]\]/g, ":$1?") // optional dynamic, [[foo]]
.replace(/\[([^\]]+)\]/g, ":$1") // dynamic, [foo]
.replace(
new RegExp(
`/page\\.(${VALID_FILE_EXTENSIONS.map((ext) => ext.slice(1)).join(