rsnext/packages/next/client/add-base-path.ts
Javi Velasco daab64c27e
Extract router utils to common functions (#37313)
* Extract `detect-domain-locale` to a util file

* Remove `pathNoQueryHash` in favor of `parsePath`

* Remove `hasPathPrefix` in favor of `pathHasPrefix`

* Remove `addPathPrefix` in favor of an existing util

* Bugfix parsing pathname

* Refactor `addLocale`

* Extract `removeLocale`

* Extract `basePath` utils

* Dynamic imports for `getDomainLocale`
2022-05-30 20:19:37 +02:00

14 lines
462 B
TypeScript

import { addPathPrefix } from '../shared/lib/router/utils/add-path-prefix'
import { normalizePathTrailingSlash } from './normalize-trailing-slash'
const basePath = (process.env.__NEXT_ROUTER_BASEPATH as string) || ''
export function addBasePath(path: string, required?: boolean): string {
if (process.env.__NEXT_MANUAL_CLIENT_BASE_PATH) {
if (!required) {
return path
}
}
return normalizePathTrailingSlash(addPathPrefix(path, basePath))
}