Skip to content

Commit

Permalink
#530304 [Nextjs][SXA] decode url for redirects (#1017)
Browse files Browse the repository at this point in the history
  • Loading branch information
sc-ruslanmatkovskyi authored May 16, 2022
1 parent 5746794 commit 4d9b264
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/sitecore-jss-nextjs/src/edge/redirects-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ export class RedirectsMiddleware {

url.search = existsRedirect.isQueryStringPreserved ? url.search : '';
url.pathname = existsRedirect.target;
const redirectUrl = decodeURIComponent(url.href);

/** return Response redirect with http code of redirect type **/
switch (existsRedirect.redirectType) {
case REDIRECT_TYPE_301:
return NextResponse.redirect(url, 301);
return NextResponse.redirect(redirectUrl, 301);
case REDIRECT_TYPE_302:
return NextResponse.redirect(url, 302);
return NextResponse.redirect(redirectUrl, 302);
case REDIRECT_TYPE_SERVER_TRANSFER:
return NextResponse.rewrite(url);
return NextResponse.rewrite(redirectUrl);
default:
return NextResponse.next();
}
Expand Down

0 comments on commit 4d9b264

Please sign in to comment.