MCPcopy
hub / github.com/vercel/next.js / removeLocale

Function removeLocale

packages/next/src/client/remove-locale.ts:3–18  ·  view source on GitHub ↗
(path: string, locale?: string)

Source from the content-addressed store, hash-verified

1import { parsePath } from '../shared/lib/router/utils/parse-path'
2
3export function removeLocale(path: string, locale?: string) {
4 if (process.env.__NEXT_I18N_SUPPORT) {
5 const { pathname } = parsePath(path)
6 const pathLower = pathname.toLowerCase()
7 const localeLower = locale?.toLowerCase()
8
9 return locale &&
10 (pathLower.startsWith(`/${localeLower}/`) ||
11 pathLower === `/${localeLower}`)
12 ? `${pathname.length === locale.length + 1 ? `/` : ``}${path.slice(
13 locale.length + 1
14 )}`
15 : path
16 }
17 return path
18}

Callers 2

changeMethod · 0.90
prefetchMethod · 0.90

Calls 4

parsePathFunction · 0.90
toLowerCaseMethod · 0.80
startsWithMethod · 0.80
sliceMethod · 0.45

Tested by

no test coverage detected