diff --git a/app/pages/error.vue b/app/pages/error.vue deleted file mode 100644 index 6de5f13..0000000 --- a/app/pages/error.vue +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - {{ errorTitle }} - - - {{ errorDescription }} - - - - - - - {{ homeButtonText }} - - - - - - - - \ No newline at end of file diff --git a/app/pages/error/index.vue b/app/pages/error/index.vue new file mode 100644 index 0000000..4549382 --- /dev/null +++ b/app/pages/error/index.vue @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/layers/middleware/init.route.global.ts b/layers/middleware/init.route.global.ts index 25ec6f0..f6e37a1 100644 --- a/layers/middleware/init.route.global.ts +++ b/layers/middleware/init.route.global.ts @@ -9,9 +9,16 @@ export default defineNuxtRouteMiddleware(async (to, _from) => { // 현재 경로에서 언어 코드 추출 // 예: /ko/about/story -> ko // 예: /en/test/page -> en - const languagePattern = /^\/([a-z]{2})(?:\/|$)/ - const match = to.path.match(languagePattern) - const currentLangCode = match ? match[1] : null + + const gameDataStore = useGameDataStore() + const gameData = gameDataStore.gameData as GameDataValue + const langCodes = gameData?.lang_codes + const currentLangCode = csrGetFinalLocale(to.path, langCodes) + + // const languagePattern = /^\/([a-z]{2})(?:\/|$)/ + // const match = to.path.match(languagePattern) + // const currentLangCode = match ? match[1] : null + console.log("🚀 777777 ~ currentLangCode:", currentLangCode) //현재 url에서 게임 도메인만 추출 const currentDomain = window.location.hostname @@ -27,11 +34,9 @@ export default defineNuxtRouteMiddleware(async (to, _from) => { const { getGameDataExternal } = useGetGameDataExternal() await getGameDataExternal(req) - const gameDataStore = useGameDataStore() - const gameData = gameDataStore.gameData as GameDataValue - const langCodes = gameData?.lang_codes + - // 허용된 언어 코드 목록 + // 허용된 언어 코드 목록≈≈ const allowedLangCodes = langCodes || [] // 현재 언어가 허용된 언어 목록에 없으면 에러 페이지로 이동 diff --git a/layers/middleware/pageData.global.ts b/layers/middleware/pageData.global.ts index 950f3a9..c16a295 100644 --- a/layers/middleware/pageData.global.ts +++ b/layers/middleware/pageData.global.ts @@ -38,8 +38,13 @@ export default defineNuxtRouteMiddleware(async (to, _from) => { const pageUrl = getPathAfterLanguage(to.path) + // error 페이지는 API 호출하지 않음 + if (pageUrl === '/error' || to.path.includes('/error')) { + return + } + // pageUrl이 빈값이거나 null이면 /brand로 리다이렉트 - if (!pageUrl || pageUrl === '' || pageUrl === '/') { + if (!pageUrl || pageUrl === '' || pageUrl === '/' || pageUrl === `/${langCode}/`) { return navigateTo(`/${langCode}/brand`, { replace: true }) } @@ -57,12 +62,9 @@ export default defineNuxtRouteMiddleware(async (to, _from) => { })) as PageDataResponse | null console.log('🚀 ~ response?.code:', response?.code) - // if(response?.code === 91003) { - // throw createError({ - // statusCode: 404, - // statusMessage: 'Page not found', - // }) - // } + if(response?.code === 91003) { + return navigateTo(`/${langCode}/error`, { external: false }) + } if (response?.code === 0 && 'value' in response) { store.setPageData(response.value)
- {{ errorDescription }} -