Skip to content

Commit 16512f8

Browse files
sc-ruslanmatkovskyiart-alexeyenko
authored andcommitted
[sitecore-jss-nextjs] The redirects with query string has been fixed #SXA-7405 (#1893)
Co-authored-by: Ruslan Matkovskyi <[email protected]> (cherry picked from commit eb833ef)
1 parent fa64d44 commit 16512f8

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Our versioning strategy is as follows:
2121
* `[templates/nextjs-sxa]` Fix missing value of field property in Title component. ([#1842](https://github.com/Sitecore/jss/pull/1842))
2222
* `[templates/nextjs-sxa]` The background image in the Container component was being generated from the image ID instead of the mediaUrl parameter. This fix changes that behavior. ([#1879](https://github.com/Sitecore/jss/pull/1879))
2323
* `[templates/nextjs-sxa]` The caption of image component has been fixed. ([#1874](https://github.com/Sitecore/jss/pull/1874))
24-
* `[sitecore-jss-nextjs]` A bug has been fixed in the redirect middleware that occurred when a user clicked on a link rendered by the Link component from the Next.js library(next/link). ([#1876](https://github.com/Sitecore/jss/pull/1876)) ([#1891](https://github.com/Sitecore/jss/pull/1891))
24+
* `[sitecore-jss-nextjs]` A bug has been fixed in the redirect middleware that occurred when a user clicked on a link rendered by the Link component from the Next.js library(next/link). ([#1876](https://github.com/Sitecore/jss/pull/1876)) ([#1891](https://github.com/Sitecore/jss/pull/1891)) ([#1893](https://github.com/Sitecore/jss/pull/1893))
2525
* `[sitecore-jss-nextjs]` Disable nextjs image optimization in edit and preview modes. This prevents rendering issues in XM Cloud Pages Edit and Preview.
2626

2727
### 🎉 New Features & Improvements

packages/sitecore-jss-nextjs/src/middleware/redirects-middleware.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,13 @@ export class RedirectsMiddleware extends MiddlewareBase {
130130
.replace(/^\/\//, '/')
131131
.split('?');
132132

133-
if (target[1]) {
134-
const movedSearchParams = existsRedirect.isQueryStringPreserved
135-
? url.search.replace(/^\?/gi, '&')
136-
: '';
137-
url.search = '?' + new URLSearchParams(`${target[1]}${movedSearchParams}`).toString();
133+
if (url.search && existsRedirect.isQueryStringPreserved) {
134+
const targetQueryString = target[1] ?? '';
135+
url.search = '?' + new URLSearchParams(`${url.search}&${targetQueryString}`).toString();
136+
} else if (target[1]) {
137+
url.search = '?' + target[1];
138+
} else {
139+
url.search = '';
138140
}
139141

140142
const prepareNewURL = new URL(`${target[0]}${url.search}`, url.origin);

0 commit comments

Comments
 (0)