diff --git a/CHANGELOG.md b/CHANGELOG.md index 28909a27ba..18cd8d352c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ Our versioning strategy is as follows: * `[templates/node-headless-ssr-proxy]` `[node-headless-ssr-proxy]` Add sc_site qs parameter to Layout Service requests by default ([#1660](https://github.com/Sitecore/jss/pull/1660)) * `[templates/nextjs-sxa]` Fixed Image component when there is using Banner variant which set property background-image when image is empty. ([#1689](https://github.com/Sitecore/jss/pull/1689)) ([#1692](https://github.com/Sitecore/jss/pull/1692)) * `[sitecore-jss-react]` `[templates/nextjs-xmcloud]` Ensure FEAAS and BYOC components can correctly use item datasources ([#1694](https://github.com/Sitecore/jss/pull/1694)) +* `[sitecore-jss-nextjs]` Fix loop error in redirect middleware when the pattern of redirect has default locale. ([#1696](https://github.com/Sitecore/jss/pull/1696)) ### 🛠 Breaking Changes diff --git a/packages/sitecore-jss-nextjs/src/middleware/redirects-middleware.ts b/packages/sitecore-jss-nextjs/src/middleware/redirects-middleware.ts index 54924cb163..7af5e05b79 100644 --- a/packages/sitecore-jss-nextjs/src/middleware/redirects-middleware.ts +++ b/packages/sitecore-jss-nextjs/src/middleware/redirects-middleware.ts @@ -173,9 +173,12 @@ export class RedirectsMiddleware extends MiddlewareBase { const redirects = await this.redirectsService.fetchRedirects(siteName); const tragetURL = req.nextUrl.pathname; const targetQS = req.nextUrl.search || ''; + const language = this.getLanguage(req); + const modifyRedirects = structuredClone(redirects); - return redirects.length - ? redirects.find((redirect: RedirectInfo) => { + return modifyRedirects.length + ? modifyRedirects.find((redirect: RedirectInfo) => { + redirect.pattern = redirect.pattern.replace(RegExp(`^[^]?/${language}/`, 'gi'), ''); redirect.pattern = `/^\/${redirect.pattern .replace(/^\/|\/$/g, '') .replace(/^\^\/|\/\$$/g, '')