export const usePathResolver = () => { const getPathAfterLanguage = (url?: string): string => { // URL이 제공되지 않으면 현재 URL 사용 const targetUrl = url || (import.meta.client ? window.location.pathname : ""); // URL에서 언어 코드 패턴을 찾아서 그 뒤의 경로를 추출 // 예: /ko/about/story -> /about/story // 예: /en/test/page -> /test/page // 예: /ko -> "" (빈 문자열) const languagePattern = /^\/[a-z]{2}\/(.+)$/; const match = targetUrl.match(languagePattern); if (match && match[1]) { return `/${match[1]}`; } // 언어 코드만 있고 뒤에 아무것도 없는 경우 (예: /ko, /en) const languageOnlyPattern = /^\/[a-z]{2}$/; if (languageOnlyPattern.test(targetUrl)) { return ""; } // 언어 코드가 없는 경우 원본 경로 그대로 반환 (이미 /로 시작) return targetUrl; }; const getCurrentPath = (): string => { if (import.meta.client) { return getPathAfterLanguage(); } return ""; }; return { getPathAfterLanguage, getCurrentPath, }; };