Files
klz-cables.com/.pnpm-store/v10/files/e3/2eaf7b292b6cc57e5dfaffda0c95cf421a4618a29d559486aecaa12a6c0f976d7d31e6d8480044f7dd7dd30a88aa6a79f8760a4b08800e875b2084f5b93763
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

37 lines
1.5 KiB
Plaintext

import { usePathname } from 'next/navigation';
import { useMemo } from 'react';
import { useLocale } from 'use-intl';
import { hasPathnamePrefixed, unprefixPathname, getLocalePrefix, getLocaleAsPrefix } from '../../shared/utils.js';
function useBasePathname(config) {
// The types aren't entirely correct here. Outside of Next.js
// `useParams` can be called, but the return type is `null`.
// Notes on `useNextPathname`:
// - Types aren't entirely correct. Outside of Next.js the
// hook will return `null` (e.g. unit tests)
// - A base path is stripped from the result
// - Rewrites *are* taken into account (i.e. the pathname
// that the user sees in the browser is returned)
const pathname = usePathname();
const locale = useLocale();
return useMemo(() => {
if (!pathname) return pathname;
let unlocalizedPathname = pathname;
const prefix = getLocalePrefix(locale, config.localePrefix);
const isPathnamePrefixed = hasPathnamePrefixed(prefix, pathname);
if (isPathnamePrefixed) {
unlocalizedPathname = unprefixPathname(pathname, prefix);
} else if (config.localePrefix.mode !== 'never' && config.localePrefix.prefixes) {
// Workaround for https://github.com/vercel/next.js/issues/73085
const localeAsPrefix = getLocaleAsPrefix(locale);
if (hasPathnamePrefixed(localeAsPrefix, pathname)) {
unlocalizedPathname = unprefixPathname(pathname, localeAsPrefix);
}
}
return unlocalizedPathname;
}, [config.localePrefix, locale, pathname]);
}
export { useBasePathname as default };