next.js/packages/next/src/shared/lib/page-path/normalize-data-path.ts
normalize-data-path.ts19 lines428 B
import { pathHasPrefix } from '../router/utils/path-has-prefix'

/**
 * strip _next/data/<build-id>/ prefix and .json suffix
 */
export function normalizeDataPath(pathname: string) {
  if (!pathHasPrefix(pathname || '/', '/_next/data')) {
    return pathname
  }
  pathname = pathname
    .replace(/\/_next\/data\/[^/]{1,}/, '')
    .replace(/\.json$/, '')

  if (pathname === '/index') {
    return '/'
  }
  return pathname
}
Quest for Codev2.0.0
/
SIGN IN