next-translate-routes-multi-domain
Version:
Flexible and translated routes for Next.js without custom server
13 lines (11 loc) • 457 B
text/typescript
import {
matchAllFilepathPartsRegex,
optionalMatchAllFilepathPartsRegex,
dynamicFilepathPartsRegex,
} from '../shared/regex'
/** Transform Next file-system synthax to path-to-regexp synthax */
export const fileNameToPath = (fileName: string) =>
fileName
.replace(optionalMatchAllFilepathPartsRegex, ':$1*') // [[...param]]
.replace(matchAllFilepathPartsRegex, ':$1+') // [...param]
.replace(dynamicFilepathPartsRegex, ':$1') // [param]