@sitecore-jss/sitecore-jss-nextjs 22.10.0-canary.8 → 22.10.0-canary.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -166,7 +166,19 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
166
166
  }
167
167
  const url = this.normalizeUrl(req.nextUrl.clone());
168
168
  if (REGEXP_ABSOLUTE_URL.test(existsRedirect.target)) {
169
- return this.dispatchRedirect(existsRedirect.target, existsRedirect.redirectType, req, response, true);
169
+ // Perform variable substitution for absolute URLs
170
+ let finalTarget = existsRedirect.target;
171
+ if ((0, utils_1.isRegexOrUrl)(existsRedirect.pattern) === 'regex') {
172
+ const matched = url.pathname
173
+ .replace(/\/*$/gi, '')
174
+ .match((0, regex_parser_1.default)(existsRedirect.pattern));
175
+ if (matched) {
176
+ finalTarget = existsRedirect.target.replace(/\$(\d+)/g, (_, index) => {
177
+ return matched[parseInt(index, 10)] || '';
178
+ });
179
+ }
180
+ }
181
+ return this.dispatchRedirect(finalTarget, existsRedirect.redirectType, req, response, true);
170
182
  }
171
183
  else {
172
184
  const isUrl = (0, utils_1.isRegexOrUrl)(existsRedirect.pattern) === 'url';
@@ -160,7 +160,19 @@ export class RedirectsMiddleware extends MiddlewareBase {
160
160
  }
161
161
  const url = this.normalizeUrl(req.nextUrl.clone());
162
162
  if (REGEXP_ABSOLUTE_URL.test(existsRedirect.target)) {
163
- return this.dispatchRedirect(existsRedirect.target, existsRedirect.redirectType, req, response, true);
163
+ // Perform variable substitution for absolute URLs
164
+ let finalTarget = existsRedirect.target;
165
+ if (isRegexOrUrl(existsRedirect.pattern) === 'regex') {
166
+ const matched = url.pathname
167
+ .replace(/\/*$/gi, '')
168
+ .match(regexParser(existsRedirect.pattern));
169
+ if (matched) {
170
+ finalTarget = existsRedirect.target.replace(/\$(\d+)/g, (_, index) => {
171
+ return matched[parseInt(index, 10)] || '';
172
+ });
173
+ }
174
+ }
175
+ return this.dispatchRedirect(finalTarget, existsRedirect.redirectType, req, response, true);
164
176
  }
165
177
  else {
166
178
  const isUrl = isRegexOrUrl(existsRedirect.pattern) === 'url';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-jss/sitecore-jss-nextjs",
3
- "version": "22.10.0-canary.8",
3
+ "version": "22.10.0-canary.9",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -72,16 +72,16 @@
72
72
  "react-dom": "^19.1.0"
73
73
  },
74
74
  "dependencies": {
75
- "@sitecore-jss/sitecore-jss": "22.10.0-canary.8",
76
- "@sitecore-jss/sitecore-jss-dev-tools": "22.10.0-canary.8",
77
- "@sitecore-jss/sitecore-jss-react": "22.10.0-canary.8",
75
+ "@sitecore-jss/sitecore-jss": "22.10.0-canary.9",
76
+ "@sitecore-jss/sitecore-jss-dev-tools": "22.10.0-canary.9",
77
+ "@sitecore-jss/sitecore-jss-react": "22.10.0-canary.9",
78
78
  "@vercel/kv": "^0.2.1",
79
79
  "regex-parser": "^2.2.11",
80
80
  "sync-disk-cache": "^2.1.0"
81
81
  },
82
82
  "description": "",
83
83
  "types": "types/index.d.ts",
84
- "gitHead": "8dbbed95dbcb81fe3f2d885d4907a6d3223469d5",
84
+ "gitHead": "db2b558f784ce412eacd2f4a26bc0e38f00fe49a",
85
85
  "files": [
86
86
  "dist",
87
87
  "types",