import { useLocale } from './useLocale'; type LocalizedPathInput = string | null | undefined; export const useLocalizedRoutes = () => { const locale = useLocale(); const localizedPath = (path: LocalizedPathInput) => { if (typeof path !== 'string' || path.trim().length === 0) { // Diagnose cases where components pass falsy / non-string hrefs (e.g. legacy localized routes, pagination links) // This log allows us to correlate console errors from Inertia with offending components. console.error('[useLocalizedRoutes] Invalid path input detected', { path, locale, stack: new Error().stack, }); return '/'; } const trimmed = path.trim(); const normalized = trimmed.startsWith('/') ? trimmed : `/${trimmed}`; // console.debug('[useLocalizedRoutes] Resolved path', { input: path, normalized, locale }); // Since prefix-free, return plain path. Locale is handled via session. return normalized; }; return { localizedPath }; };