Skip to content

Commit

Permalink
fix dynamic routes exported files under index folder
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Dec 13, 2021
1 parent 438ee96 commit d3e23e6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/next/export/worker.ts
Expand Up @@ -215,8 +215,8 @@ export default async function exportPage({
subFolders ? `${_path}${sep}index.html` : `${_path}.html`
let htmlFilename = getHtmlFilename(filePath)

const pageExt = extname(page)
const pathExt = extname(path)
const pageExt = isDynamic ? '' : extname(page)
const pathExt = isDynamic ? '' : extname(path)
// Make sure page isn't a folder with a dot in the name e.g. `v1.2`
if (pageExt !== pathExt && pathExt !== '') {
const isBuiltinPaths = ['/500', '/404'].some(
Expand Down
4 changes: 3 additions & 1 deletion packages/next/server/denormalize-page-path.ts
@@ -1,10 +1,12 @@
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/')) {
if (page.startsWith('/index/') && !isDynamicRoute(page)) {
page = page.slice(6)
} else if (page === '/index') {
page = '/'
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server/normalize-page-path.ts
Expand Up @@ -6,7 +6,7 @@ export function normalizePagePath(page: string): string {
// If the page is `/` we need to append `/index`, otherwise the returned directory root will be bundles instead of pages
if (page === '/') {
page = '/index'
} else if (/^\/index(\/|$)/.test(page)) {
} else if (/^\/index(\/|$)$/.test(page)) {
page = `/index${page}`
}
// Resolve on anything that doesn't start with `/`
Expand Down
@@ -1,4 +1,7 @@
// Translate a pages asset path (relative from a common prefix) back into its logical route

import { isDynamicRoute } from './is-dynamic'

// "asset path" being its javascript file, data file, prerendered html,...
export default function getRouteFromAssetPath(
assetPath: string,
Expand All @@ -7,7 +10,7 @@ export default function getRouteFromAssetPath(
assetPath = assetPath.replace(/\\/g, '/')
assetPath =
ext && assetPath.endsWith(ext) ? assetPath.slice(0, -ext.length) : assetPath
if (assetPath.startsWith('/index/')) {
if (assetPath.startsWith('/index/') && !isDynamicRoute(assetPath)) {
assetPath = assetPath.slice(6)
} else if (assetPath === '/index') {
assetPath = '/'
Expand Down
3 changes: 3 additions & 0 deletions test/integration/dynamic-routing/pages/index/[...slug].js
@@ -0,0 +1,3 @@
export default function page() {
return 'index/[...slug]'
}

0 comments on commit d3e23e6

Please sign in to comment.