Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#589841: [sitecore-jss-nextjs] use token in redirects. fixed pattern #1561

Merged
merged 4 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Our versioning strategy is as follows:
* `[sitecore-jss-react]` Remove use of reactDom/server from React Image ([1544](https://github.com/Sitecore/jss/pull/1544))
* `[sitecore-jss-nextjs]` Referrer is not captured by Personalize middleware ([#1542](https://github.com/Sitecore/jss/pull/1542))
* `[sitecore.jss-react]` Fix double placeholder in Experience Editor in production mode ([#1557](https://github.com/Sitecore/jss/pull/1557))
* `[sitecore-jss-nextjs]` Fix of redirects middleware. Add possible to use tokens like $1, $2, $3, etc. ([#1547](https://github.com/Sitecore/jss/pull/1547)) ([#1559](https://github.com/Sitecore/jss/pull/1559))
* `[sitecore-jss-nextjs]` Fix of redirects middleware. Add possible to use tokens like $1, $2, $3, etc. ([#1547](https://github.com/Sitecore/jss/pull/1547)) ([#1559](https://github.com/Sitecore/jss/pull/1559)) ([#1561](https://github.com/Sitecore/jss/pull/1561))

## 21.2.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,18 @@ export class RedirectsMiddleware extends MiddlewareBase {

return redirects.length
? redirects.find((redirect: RedirectInfo) => {
const pattern = `/^\/${redirect.pattern
redirect.pattern = `/^\/${redirect.pattern
.replace(/^\/|\/$/g, '')
.replace(/^\^\/|\/\$$/g, '')
.replace(/^\^|\$$/g, '')}$/gi`;

return (
(regexParser(pattern).test(tragetURL) ||
regexParser(pattern).test(`${tragetURL}${targetQS}`) ||
regexParser(pattern).test(`/${req.nextUrl.locale}${tragetURL}`) ||
regexParser(pattern).test(`/${req.nextUrl.locale}${tragetURL}${targetQS}`)) &&
(regexParser(redirect.pattern).test(tragetURL) ||
regexParser(redirect.pattern).test(`${tragetURL}${targetQS}`) ||
regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${tragetURL}`) ||
regexParser(redirect.pattern).test(
`/${req.nextUrl.locale}${tragetURL}${targetQS}`
)) &&
(redirect.locale
? redirect.locale.toLowerCase() === req.nextUrl.locale.toLowerCase()
: true)
Expand Down