Skip to content

Commit

Permalink
fix: Compare also decoded Url with a route (#1816)
Browse files Browse the repository at this point in the history
This adds an additional check for the route to check if a redirect is needed.
Before a encoded url part like an 'ä' or a whitespace would have created a endless loop.

Co-authored-by: Sven Kröger <[email protected]>
  • Loading branch information
szwenni and Sven Kröger authored Jan 24, 2023
1 parent 041c170 commit 920a4fe
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/runtime/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,16 @@ export function detectRedirect<Context extends NuxtApp = NuxtApp>(
// the current route could be 404 in which case attempt to find matching route using the full path since
// "switchLocalePath" can only find routes if the current route exists.
const { fullPath } = route
const decodedRoute = decodeURI(fullPath)
const routePath = context.$switchLocalePath(targetLocale) || context.$localePath(fullPath, targetLocale)
__DEBUG__ && console.log('detectRedirect: calculate routePath -> ', routePath, fullPath)
if (isString(routePath) && routePath && routePath !== fullPath && !routePath.startsWith('//')) {
if (
isString(routePath) &&
routePath &&
routePath !== fullPath &&
routePath !== decodedRoute &&
!routePath.startsWith('//')
) {
redirectPath = routePath
}
}
Expand Down

0 comments on commit 920a4fe

Please sign in to comment.