next.js/packages/next/src/shared/lib/router/utils/add-path-prefix.ts
add-path-prefix.ts15 lines391 B
import { parsePath } from './parse-path'

/**
 * Adds the provided prefix to the given path. It first ensures that the path
 * is indeed starting with a slash.
 */
export function addPathPrefix(path: string, prefix?: string) {
  if (!path.startsWith('/') || !prefix) {
    return path
  }

  const { pathname, query, hash } = parsePath(path)
  return `${prefix}${pathname}${query}${hash}`
}
Quest for Codev2.0.0
/
SIGN IN