rsnext/packages/next/server/denormalize-page-path.ts
Jiachi Liu 10d814d31a
Fix dynamic routes with pages under index folder (#32440)
Fixes incorrect generated manifest and generated directory for `index/[...dynamic]` pages

Too much normalizing adding extra `index/` prefix to `index/[...dynamic]` routes which lead to the incorrected generated routes like `.next/server/pages/index/index/index/[...dynamic]`

## Bug

Fixes https://github.com/vercel/customer-issues/issues/146

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2021-12-13 20:36:31 +00:00

15 lines
394 B
TypeScript

import { isDynamicRoute } from '../shared/lib/router/utils'
export function normalizePathSep(path: string): string {
return path.replace(/\\/g, '/')
}
export function denormalizePagePath(page: string) {
page = normalizePathSep(page)
if (page.startsWith('/index/') && !isDynamicRoute(page)) {
page = page.slice(6)
} else if (page === '/index') {
page = '/'
}
return page
}