Skip to content

Commit

Permalink
[sitecore-jss-nextjs] The redirects with query string has been fixed …
Browse files Browse the repository at this point in the history
…#SXA-7405 (#1893)

Co-authored-by: Ruslan Matkovskyi <[email protected]>
  • Loading branch information
sc-ruslanmatkovskyi and Ruslan Matkovskyi authored Aug 19, 2024
1 parent ef8d996 commit eb833ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Our versioning strategy is as follows:
* `[templates/nextjs-sxa]` Fix missing value of field property in Title component. ([#1842](https://github.com/Sitecore/jss/pull/1842))
* `[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))
* `[templates/nextjs-sxa]` The caption of image component has been fixed. ([#1874](https://github.com/Sitecore/jss/pull/1874))
* `[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))
* `[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))
* `[sitecore-jss-nextjs]` Disable nextjs image optimization in edit and preview modes. This prevents rendering issues in XM Cloud Pages Edit and Preview.

### 🎉 New Features & Improvements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ export class RedirectsMiddleware extends MiddlewareBase {
.replace(/^\/\//, '/')
.split('?');

if (target[1]) {
const movedSearchParams = existsRedirect.isQueryStringPreserved
? url.search.replace(/^\?/gi, '&')
: '';
url.search = '?' + new URLSearchParams(`${target[1]}${movedSearchParams}`).toString();
if (url.search && existsRedirect.isQueryStringPreserved) {
const targetQueryString = target[1] ?? '';
url.search = '?' + new URLSearchParams(`${url.search}&${targetQueryString}`).toString();
} else if (target[1]) {
url.search = '?' + target[1];
} else {
url.search = '';
}

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

0 comments on commit eb833ef

Please sign in to comment.