523704b83f
* Do not exclude internal _next request in middleware * Allow for `NextURL` to parse prefetch requests * Add test for middleware data prefetch * Refactor `hasBasePath` and `replaceBasePath` * Refactor `removeTrailingSlash` * Refactor parsed next url to use `getNextPathnameInfo` * Allow to configure `NextURL` * Ensure middleware rewrites with always with a locale Co-authored-by: JJ Kasper <jj@jjsweb.site>
16 lines
618 B
TypeScript
16 lines
618 B
TypeScript
import { pathHasPrefix } from './path-has-prefix'
|
|
|
|
/**
|
|
* Given a path and a prefix it will remove the prefix when it exists in the
|
|
* given path. It ensures it matches exactly without containing extra chars
|
|
* and if the prefix is not there it will be noop.
|
|
* @param path The path to remove the prefix from.
|
|
* @param prefix The prefix to be removed.
|
|
*/
|
|
export function removePathPrefix(path: string, prefix: string): string {
|
|
if (pathHasPrefix(path, prefix)) {
|
|
const withoutPrefix = path.slice(prefix.length)
|
|
return withoutPrefix.startsWith('/') ? withoutPrefix : `/${withoutPrefix}`
|
|
}
|
|
return path
|
|
}
|