fix. /home으로 리다이렉트 처리 되도록 수정, csr에서 이동되어 하이드레이션 나던 부분 수정

This commit is contained in:
clkim
2025-11-19 16:18:53 +09:00
parent 1596f874ff
commit 26780143d1
3 changed files with 48 additions and 23 deletions

View File

@@ -10,12 +10,13 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
const serverGameData = getGameDataFromServer()
const gameDataStore = useGameDataStore()
const { setGameData } = gameDataStore
if (serverGameData) {
setGameData(serverGameData)
}
try{
try {
// 서버 사이드에서는 스킵
if (!import.meta.client) {
return
@@ -34,7 +35,7 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
// 쿼리스트링에서 f 파라미터 값 추출 (CSR용)
// const fValue = (to.query.f as string) || ''
// 미리보기 API 호출 처리
// let finalGameDomain = currentDomain
// if (fValue === 'preview') {
@@ -52,9 +53,12 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
// const { getGameDataExternal } = useGetGameDataExternal()
// await getGameDataExternal(req)
// error 페이지는 API 호출하지 않음
if (pageUrl === '/error' || to.path.includes('/error') || to.path.includes('/inspection')) {
if (
pageUrl === '/error' ||
to.path.includes('/error') ||
to.path.includes('/inspection')
) {
return
}
@@ -64,17 +68,17 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
// 현재 언어가 허용된 언어 목록에 없으면 에러 페이지로 이동
if (currentLangCode && !allowedLangCodes.includes(currentLangCode)) {
return navigateTo(`/${currentLangCode}/error`, { external: true })
}
} catch (error) {
console.error(error)
showError(createError({
statusCode: error.statusCode,
statusMessage: error.message,
fatal: false, // 즉시 에러 페이지로
data: { reason: 'post-not-found' }
}))
showError(
createError({
statusCode: error?.statusCode || error?.status || 500,
statusMessage:
error?.statusMessage || error?.message || 'Internal Server Error',
fatal: false, // 즉시 에러 페이지로
data: { reason: 'post-not-found' },
})
)
}
})

View File

@@ -29,17 +29,16 @@ export default defineNuxtRouteMiddleware(async (to, _from) => {
}
const pageUrl = getPathAfterLanguage(to.path)
console.log('🚀 ~ pageUrl:', pageUrl)
// pageUrl이 빈값이거나 null이면 /brand로 리다이렉트
if (
!pageUrl ||
pageUrl === '' ||
pageUrl === '/' ||
pageUrl === `/${langCode}/`
) {
return navigateTo(`/${langCode}/brand`, { external: false })
}
// if (
// !pageUrl ||
// pageUrl === '' ||
// pageUrl === '/' ||
// pageUrl === `/${langCode}/`
// ) {
// return navigateTo(`/${langCode}/brand`, { external: false })
// }
// error 페이지는 API 호출하지 않음
if (pageUrl === '/error' || to.path.includes('/error')) {

View File

@@ -414,6 +414,28 @@ export default defineEventHandler(async event => {
}
}
}
// -------------------------------------------------------------------------------
// [Root Path Redirect to /home]
// 언어 코드만 있는 경로(예: /ko, /ko/)를 /home 리다이렉트
// -------------------------------------------------------------------------------
const normalizedPath = fullPath.endsWith('/')
? fullPath.slice(0, -1)
: fullPath
const localePath = `/${finalLocale}`
if (normalizedPath === localePath) {
const defaultPath = `/${finalLocale}/home`
const queryString = event?.node.req.url?.includes('?')
? '?' + event.node.req.url.split('?')[1]
: ''
if (!event.node.res.headersSent && !event.node.res.writableEnded) {
event.node.res.statusCode = 302
event.node.res.setHeader('Location', defaultPath + queryString)
event.node.res.end()
return
}
}
// -------------------------------------------------------------------------------
// [Locale Middleware]
// -------------------------------------------------------------------------------