Files

22 lines
569 B
TypeScript

import { hasLocale } from 'next-intl';
import { routing } from './routing';
/**
* Internal hrefs in page content are locale-prefixed (`/{locale}/{path}`);
* when the site serves unprefixed URLs, the prefix is stripped at render
* time so navigation does not bounce through the proxy redirect.
*/
export function toPublicHref(href: string): string {
if (routing.localePrefix !== 'never') {
return href;
}
const [, first = '', ...rest] = href.split('/');
if (!hasLocale(routing.locales, first)) {
return href;
}
return `/${rest.join('/')}`;
}