Skip to content

Commit

Permalink
fix: loop redirection (nuxt-modules#1854)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon authored Feb 12, 2023
1 parent 9e32424 commit 225e0b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 18 additions & 3 deletions src/runtime/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,24 @@ export async function navigate<Context extends NuxtApp = NuxtApp>(
let { redirectPath } = args

__DEBUG__ && console.log('navigate options ', status, rootRedirect, differentDomains, skipSettingLocaleOnNavigate)
__DEBUG__ && console.log('navigate isSSG', isSSG)

if (route.path === '/' && rootRedirect) {
if (isString(rootRedirect)) {
redirectPath = rootRedirect
redirectPath = '/' + rootRedirect
} else if (isRootRedirectOptions(rootRedirect)) {
redirectPath = '/' + rootRedirect.path
status = rootRedirect.statusCode
}
__DEBUG__ && console.log('navigate: rootRedirect mode redirectPath -> ', redirectPath, ' status -> ', status)
return navigateTo(redirectPath, { redirectCode: status })
if (isSSG && process.client) {
if (window.location.pathname !== redirectPath) {
window.location.assign(redirectPath)
}
return
} else {
return navigateTo(redirectPath, { redirectCode: status })
}
}

if (process.client && skipSettingLocaleOnNavigate) {
Expand All @@ -393,7 +401,14 @@ export async function navigate<Context extends NuxtApp = NuxtApp>(

if (!differentDomains) {
if (redirectPath) {
return navigateTo(redirectPath, { redirectCode: status })
if (isSSG && process.client) {
if (window.location.pathname !== redirectPath) {
window.location.assign(redirectPath)
}
return
} else {
return navigateTo(redirectPath, { redirectCode: status })
}
}
} else {
const state = useRedirectState()
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineConfig({
threads: false,
testTimeout: 300000,
deps: {
inline: [/@nuxt\/test-utils-edge/]
inline: [/@nuxt\/test-utils/]
}
}
})

0 comments on commit 225e0b6

Please sign in to comment.