next-intl 3.14.1 → 3.15.0

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.
Files changed (133) hide show
  1. package/dist/development/config.js +1 -1
  2. package/dist/development/middleware/config.js +17 -0
  3. package/dist/development/middleware/getAlternateLinksHeaderValue.js +8 -7
  4. package/dist/development/middleware/middleware.js +69 -83
  5. package/dist/development/middleware/resolveLocale.js +5 -6
  6. package/dist/development/middleware/syncCookie.js +19 -0
  7. package/dist/development/middleware/utils.js +58 -30
  8. package/dist/development/navigation/react-client/ClientLink.js +7 -2
  9. package/dist/development/navigation/react-client/createLocalizedPathnamesNavigation.js +18 -16
  10. package/dist/development/navigation/react-client/createSharedPathnamesNavigation.js +17 -12
  11. package/dist/development/navigation/react-client/redirects.js +32 -0
  12. package/dist/development/navigation/react-client/useBasePathname.js +12 -4
  13. package/dist/development/navigation/react-client/useBaseRouter.js +8 -3
  14. package/dist/development/navigation/react-server/ServerLink.js +7 -1
  15. package/dist/development/navigation/react-server/createLocalizedPathnamesNavigation.js +15 -19
  16. package/dist/development/navigation/react-server/createSharedPathnamesNavigation.js +11 -10
  17. package/dist/development/navigation/react-server/redirects.js +24 -0
  18. package/dist/development/navigation/shared/BaseLink.js +6 -5
  19. package/dist/development/navigation/shared/config.js +30 -0
  20. package/dist/development/navigation/shared/redirects.js +22 -0
  21. package/dist/development/navigation/shared/utils.js +2 -4
  22. package/dist/development/routing/config.js +18 -0
  23. package/dist/development/routing.js +2 -0
  24. package/dist/development/server/react-server/RequestLocale.js +1 -1
  25. package/dist/development/shared/utils.js +26 -14
  26. package/dist/esm/config.js +1 -1
  27. package/dist/esm/middleware/config.js +1 -0
  28. package/dist/esm/middleware/getAlternateLinksHeaderValue.js +1 -1
  29. package/dist/esm/middleware/middleware.js +1 -1
  30. package/dist/esm/middleware/resolveLocale.js +1 -1
  31. package/dist/esm/middleware/syncCookie.js +1 -0
  32. package/dist/esm/middleware/utils.js +1 -1
  33. package/dist/esm/navigation/react-client/ClientLink.js +1 -1
  34. package/dist/esm/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
  35. package/dist/esm/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
  36. package/dist/esm/navigation/react-client/redirects.js +1 -0
  37. package/dist/esm/navigation/react-client/useBasePathname.js +1 -1
  38. package/dist/esm/navigation/react-client/useBaseRouter.js +1 -1
  39. package/dist/esm/navigation/react-server/ServerLink.js +1 -1
  40. package/dist/esm/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -1
  41. package/dist/esm/navigation/react-server/createSharedPathnamesNavigation.js +1 -1
  42. package/dist/esm/navigation/react-server/redirects.js +1 -0
  43. package/dist/esm/navigation/shared/BaseLink.js +1 -1
  44. package/dist/esm/navigation/shared/config.js +1 -0
  45. package/dist/esm/navigation/shared/redirects.js +1 -0
  46. package/dist/esm/navigation/shared/utils.js +1 -1
  47. package/dist/esm/routing/config.js +1 -0
  48. package/dist/esm/routing.js +1 -0
  49. package/dist/esm/server/react-server/RequestLocale.js +1 -1
  50. package/dist/esm/shared/utils.js +1 -1
  51. package/dist/production/config.js +1 -1
  52. package/dist/production/middleware/config.js +1 -0
  53. package/dist/production/middleware/getAlternateLinksHeaderValue.js +1 -1
  54. package/dist/production/middleware/middleware.js +1 -1
  55. package/dist/production/middleware/resolveLocale.js +1 -1
  56. package/dist/production/middleware/syncCookie.js +1 -0
  57. package/dist/production/middleware/utils.js +1 -1
  58. package/dist/production/navigation/react-client/ClientLink.js +1 -1
  59. package/dist/production/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
  60. package/dist/production/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
  61. package/dist/production/navigation/react-client/redirects.js +1 -0
  62. package/dist/production/navigation/react-client/useBasePathname.js +1 -1
  63. package/dist/production/navigation/react-client/useBaseRouter.js +1 -1
  64. package/dist/production/navigation/react-server/ServerLink.js +1 -1
  65. package/dist/production/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -1
  66. package/dist/production/navigation/react-server/createSharedPathnamesNavigation.js +1 -1
  67. package/dist/production/navigation/react-server/redirects.js +1 -0
  68. package/dist/production/navigation/shared/BaseLink.js +1 -1
  69. package/dist/production/navigation/shared/config.js +1 -0
  70. package/dist/production/navigation/shared/redirects.js +1 -0
  71. package/dist/production/navigation/shared/utils.js +1 -1
  72. package/dist/production/routing/config.js +1 -0
  73. package/dist/production/routing.js +1 -0
  74. package/dist/production/server/react-server/RequestLocale.js +1 -1
  75. package/dist/production/shared/utils.js +1 -1
  76. package/dist/routing.js +7 -0
  77. package/dist/types/src/middleware/config.d.ts +18 -0
  78. package/dist/types/src/middleware/getAlternateLinksHeaderValue.d.ts +6 -6
  79. package/dist/types/src/middleware/middleware.d.ts +3 -3
  80. package/dist/types/src/middleware/resolveLocale.d.ts +6 -6
  81. package/dist/types/src/middleware/syncCookie.d.ts +2 -0
  82. package/dist/types/src/middleware/utils.d.ts +19 -12
  83. package/dist/types/src/navigation/react-client/ClientLink.d.ts +10 -7
  84. package/dist/types/src/navigation/react-client/createLocalizedPathnamesNavigation.d.ts +21 -22
  85. package/dist/types/src/navigation/react-client/createSharedPathnamesNavigation.d.ts +22 -10
  86. package/dist/types/src/navigation/react-client/index.d.ts +3 -1
  87. package/dist/types/src/navigation/react-client/redirects.d.ts +10 -0
  88. package/dist/types/src/navigation/react-client/useBasePathname.d.ts +2 -1
  89. package/dist/types/src/navigation/react-client/useBaseRouter.d.ts +7 -7
  90. package/dist/types/src/navigation/react-server/ServerLink.d.ts +5 -4
  91. package/dist/types/src/navigation/react-server/createLocalizedPathnamesNavigation.d.ts +14 -15
  92. package/dist/types/src/navigation/react-server/createSharedPathnamesNavigation.d.ts +4 -6
  93. package/dist/types/src/navigation/react-server/index.d.ts +1 -1
  94. package/dist/types/src/navigation/react-server/redirects.d.ts +10 -0
  95. package/dist/types/src/navigation/shared/BaseLink.d.ts +3 -2
  96. package/dist/types/src/navigation/shared/config.d.ts +24 -0
  97. package/dist/types/src/navigation/shared/redirects.d.ts +11 -0
  98. package/dist/types/src/navigation/shared/utils.d.ts +10 -10
  99. package/dist/types/src/routing/config.d.ts +14 -0
  100. package/dist/types/src/routing/index.d.ts +2 -0
  101. package/dist/types/src/routing/types.d.ts +23 -0
  102. package/dist/types/src/routing.d.ts +1 -0
  103. package/dist/types/src/shared/types.d.ts +0 -5
  104. package/dist/types/src/shared/utils.d.ts +10 -7
  105. package/package.json +16 -6
  106. package/routing.d.ts +1 -0
  107. package/dist/development/navigation/react-client/clientPermanentRedirect.js +0 -25
  108. package/dist/development/navigation/react-client/clientRedirect.js +0 -25
  109. package/dist/development/navigation/react-server/serverPermanentRedirect.js +0 -19
  110. package/dist/development/navigation/react-server/serverRedirect.js +0 -19
  111. package/dist/development/navigation/shared/basePermanentRedirect.js +0 -16
  112. package/dist/development/navigation/shared/baseRedirect.js +0 -16
  113. package/dist/esm/navigation/react-client/clientPermanentRedirect.js +0 -1
  114. package/dist/esm/navigation/react-client/clientRedirect.js +0 -1
  115. package/dist/esm/navigation/react-server/serverPermanentRedirect.js +0 -1
  116. package/dist/esm/navigation/react-server/serverRedirect.js +0 -1
  117. package/dist/esm/navigation/shared/basePermanentRedirect.js +0 -1
  118. package/dist/esm/navigation/shared/baseRedirect.js +0 -1
  119. package/dist/production/navigation/react-client/clientPermanentRedirect.js +0 -1
  120. package/dist/production/navigation/react-client/clientRedirect.js +0 -1
  121. package/dist/production/navigation/react-server/serverPermanentRedirect.js +0 -1
  122. package/dist/production/navigation/react-server/serverRedirect.js +0 -1
  123. package/dist/production/navigation/shared/basePermanentRedirect.js +0 -1
  124. package/dist/production/navigation/shared/baseRedirect.js +0 -1
  125. package/dist/types/src/middleware/NextIntlMiddlewareConfig.d.ts +0 -31
  126. package/dist/types/src/navigation/react-client/clientPermanentRedirect.d.ts +0 -6
  127. package/dist/types/src/navigation/react-client/clientRedirect.d.ts +0 -6
  128. package/dist/types/src/navigation/react-server/serverPermanentRedirect.d.ts +0 -6
  129. package/dist/types/src/navigation/react-server/serverRedirect.d.ts +0 -6
  130. package/dist/types/src/navigation/shared/basePermanentRedirect.d.ts +0 -7
  131. package/dist/types/src/navigation/shared/baseRedirect.d.ts +0 -7
  132. /package/dist/types/test/navigation/shared/{basePermanentRedirect.test.d.ts → redirects.test.d.ts} +0 -0
  133. /package/dist/types/test/{navigation/shared/baseRedirect.test.d.ts → routing/types.test.d.ts} +0 -0
@@ -4,9 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
6
  var React = require('react');
7
+ var config = require('../shared/config.js');
7
8
  var ClientLink = require('./ClientLink.js');
8
- var clientPermanentRedirect = require('./clientPermanentRedirect.js');
9
- var clientRedirect = require('./clientRedirect.js');
9
+ var redirects = require('./redirects.js');
10
10
  var useBasePathname = require('./useBasePathname.js');
11
11
  var useBaseRouter = require('./useBaseRouter.js');
12
12
 
@@ -14,11 +14,12 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
14
 
15
15
  var React__default = /*#__PURE__*/_interopDefault(React);
16
16
 
17
- function createSharedPathnamesNavigation(opts) {
17
+ function createSharedPathnamesNavigation(input) {
18
+ const config$1 = config.receiveSharedNavigationRoutingConfig(input);
18
19
  function Link(props, ref) {
19
20
  return /*#__PURE__*/React__default.default.createElement(ClientLink.default, _rollupPluginBabelHelpers.extends({
20
21
  ref: ref,
21
- localePrefix: opts === null || opts === void 0 ? void 0 : opts.localePrefix
22
+ localePrefix: config$1.localePrefix
22
23
  }, props));
23
24
  }
24
25
  const LinkWithRef = /*#__PURE__*/React.forwardRef(Link);
@@ -27,30 +28,34 @@ function createSharedPathnamesNavigation(opts) {
27
28
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
28
29
  args[_key - 1] = arguments[_key];
29
30
  }
30
- return clientRedirect.default({
31
- ...opts,
32
- pathname
31
+ return redirects.clientRedirect({
32
+ pathname,
33
+ localePrefix: config$1.localePrefix
33
34
  }, ...args);
34
35
  }
35
36
  function permanentRedirect(pathname) {
36
37
  for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
37
38
  args[_key2 - 1] = arguments[_key2];
38
39
  }
39
- return clientPermanentRedirect.default({
40
- ...opts,
41
- pathname
40
+ return redirects.clientPermanentRedirect({
41
+ pathname,
42
+ localePrefix: config$1.localePrefix
42
43
  }, ...args);
43
44
  }
44
45
  function usePathname() {
46
+ const result = useBasePathname.default(config$1.localePrefix);
45
47
  // @ts-expect-error -- Mirror the behavior from Next.js, where `null` is returned when `usePathname` is used outside of Next, but the types indicate that a string is always returned.
46
- return useBasePathname.default();
48
+ return result;
49
+ }
50
+ function useRouter() {
51
+ return useBaseRouter.default(config$1.localePrefix);
47
52
  }
48
53
  return {
49
54
  Link: LinkWithRef,
50
55
  redirect,
51
56
  permanentRedirect,
52
57
  usePathname,
53
- useRouter: useBaseRouter.default
58
+ useRouter
54
59
  };
55
60
  }
56
61
 
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var useLocale = require('../../react-client/useLocale.js');
6
+ var redirects = require('../shared/redirects.js');
7
+
8
+ function createRedirectFn(redirectFn) {
9
+ return function clientRedirect(params) {
10
+ let locale;
11
+ try {
12
+ // eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context here is fine, since `redirect` should be called during render
13
+ locale = useLocale.default();
14
+ } catch (e) {
15
+ {
16
+ throw new Error('`redirect()` and `permanentRedirect()` can only be called during render. To redirect in an event handler or similar, you can use `useRouter()` instead.');
17
+ }
18
+ }
19
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
20
+ args[_key - 1] = arguments[_key];
21
+ }
22
+ return redirectFn({
23
+ ...params,
24
+ locale
25
+ }, ...args);
26
+ };
27
+ }
28
+ const clientRedirect = createRedirectFn(redirects.baseRedirect);
29
+ const clientPermanentRedirect = createRedirectFn(redirects.basePermanentRedirect);
30
+
31
+ exports.clientPermanentRedirect = clientPermanentRedirect;
32
+ exports.clientRedirect = clientRedirect;
@@ -21,17 +21,25 @@ var utils = require('../../shared/utils.js');
21
21
  * const pathname = usePathname();
22
22
  * ```
23
23
  */
24
- function useBasePathname() {
24
+ function useBasePathname(localePrefix) {
25
25
  // The types aren't entirely correct here. Outside of Next.js
26
26
  // `useParams` can be called, but the return type is `null`.
27
+
28
+ // Notes on `useNextPathname`:
29
+ // - Types aren't entirely correct. Outside of Next.js the
30
+ // hook will return `null` (e.g. unit tests)
31
+ // - A base path is stripped from the result
32
+ // - Rewrites *are* taken into account (i.e. the pathname
33
+ // that the user sees in the browser is returned)
27
34
  const pathname = navigation.usePathname();
28
35
  const locale = useLocale.default();
29
36
  return React.useMemo(() => {
30
37
  if (!pathname) return pathname;
31
- const isPathnamePrefixed = utils.hasPathnamePrefixed(locale, pathname);
32
- const unlocalizedPathname = isPathnamePrefixed ? utils.unlocalizePathname(pathname, locale) : pathname;
38
+ const prefix = utils.getLocalePrefix(locale, localePrefix);
39
+ const isPathnamePrefixed = utils.hasPathnamePrefixed(prefix, pathname);
40
+ const unlocalizedPathname = isPathnamePrefixed ? utils.unprefixPathname(pathname, prefix) : pathname;
33
41
  return unlocalizedPathname;
34
- }, [locale, pathname]);
42
+ }, [locale, localePrefix, pathname]);
35
43
  }
36
44
 
37
45
  exports.default = useBasePathname;
@@ -28,7 +28,7 @@ var utils = require('../shared/utils.js');
28
28
  * router.push('/about', {locale: 'de'});
29
29
  * ```
30
30
  */
31
- function useBaseRouter() {
31
+ function useBaseRouter(localePrefix) {
32
32
  const router = navigation.useRouter();
33
33
  const locale = useLocale.default();
34
34
  const pathname = navigation.usePathname();
@@ -37,7 +37,12 @@ function useBaseRouter() {
37
37
  let curPathname = window.location.pathname;
38
38
  const basePath = utils.getBasePath(pathname);
39
39
  if (basePath) curPathname = curPathname.replace(basePath, '');
40
- return utils$1.localizeHref(href, nextLocale || locale, locale, curPathname);
40
+ const targetLocale = nextLocale || locale;
41
+
42
+ // We generate a prefix in any case, but decide
43
+ // in `localizeHref` if we apply it or not
44
+ const prefix = utils$1.getLocalePrefix(targetLocale, localePrefix);
45
+ return utils$1.localizeHref(href, targetLocale, locale, curPathname, prefix);
41
46
  }
42
47
  function createHandler(fn) {
43
48
  return function handler(href, options) {
@@ -61,7 +66,7 @@ function useBaseRouter() {
61
66
  replace: createHandler(router.replace),
62
67
  prefetch: createHandler(router.prefetch)
63
68
  };
64
- }, [locale, pathname, router]);
69
+ }, [locale, localePrefix, pathname, router]);
65
70
  }
66
71
 
67
72
  exports.default = useBaseRouter;
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
6
  var React = require('react');
7
+ var utils = require('../../shared/utils.js');
7
8
  var BaseLink = require('../shared/BaseLink.js');
8
9
  var getLocale = require('../../server/react-server/getLocale.js');
9
10
 
@@ -14,10 +15,15 @@ var React__default = /*#__PURE__*/_interopDefault(React);
14
15
  async function ServerLink(_ref) {
15
16
  let {
16
17
  locale,
18
+ localePrefix,
17
19
  ...rest
18
20
  } = _ref;
21
+ const finalLocale = locale || (await getLocale.default());
22
+ const prefix = utils.getLocalePrefix(finalLocale, localePrefix);
19
23
  return /*#__PURE__*/React__default.default.createElement(BaseLink.default, _rollupPluginBabelHelpers.extends({
20
- locale: locale || (await getLocale.default())
24
+ locale: finalLocale,
25
+ localePrefixMode: localePrefix.mode,
26
+ prefix: prefix
21
27
  }, rest));
22
28
  }
23
29
 
@@ -5,27 +5,23 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
6
  var React = require('react');
7
7
  var RequestLocale = require('../../server/react-server/RequestLocale.js');
8
+ var config = require('../shared/config.js');
8
9
  var utils = require('../shared/utils.js');
9
10
  var ServerLink = require('./ServerLink.js');
10
- var serverPermanentRedirect = require('./serverPermanentRedirect.js');
11
- var serverRedirect = require('./serverRedirect.js');
11
+ var redirects = require('./redirects.js');
12
12
 
13
13
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
14
 
15
15
  var React__default = /*#__PURE__*/_interopDefault(React);
16
16
 
17
- function createLocalizedPathnamesNavigation(_ref) {
18
- let {
19
- localePrefix,
20
- locales,
21
- pathnames
22
- } = _ref;
23
- function Link(_ref2) {
17
+ function createLocalizedPathnamesNavigation(input) {
18
+ const config$1 = config.receiveLocalizedNavigationRoutingConfig(input);
19
+ function Link(_ref) {
24
20
  let {
25
21
  href,
26
22
  locale,
27
23
  ...rest
28
- } = _ref2;
24
+ } = _ref;
29
25
  const defaultLocale = RequestLocale.getRequestLocale();
30
26
  const finalLocale = locale || defaultLocale;
31
27
  return /*#__PURE__*/React__default.default.createElement(ServerLink.default, _rollupPluginBabelHelpers.extends({
@@ -35,10 +31,10 @@ function createLocalizedPathnamesNavigation(_ref) {
35
31
  pathname: href,
36
32
  // @ts-expect-error -- This is ok
37
33
  params: typeof href === 'object' ? href.params : undefined,
38
- pathnames
34
+ pathnames: config$1.pathnames
39
35
  }),
40
36
  locale: locale,
41
- localePrefix: localePrefix
37
+ localePrefix: config$1.localePrefix
42
38
  }, rest));
43
39
  }
44
40
  function redirect(href) {
@@ -50,8 +46,8 @@ function createLocalizedPathnamesNavigation(_ref) {
50
46
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
51
47
  args[_key - 1] = arguments[_key];
52
48
  }
53
- return serverRedirect.default({
54
- localePrefix,
49
+ return redirects.serverRedirect({
50
+ localePrefix: config$1.localePrefix,
55
51
  pathname
56
52
  }, ...args);
57
53
  }
@@ -64,20 +60,20 @@ function createLocalizedPathnamesNavigation(_ref) {
64
60
  for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
65
61
  args[_key2 - 1] = arguments[_key2];
66
62
  }
67
- return serverPermanentRedirect.default({
68
- localePrefix,
63
+ return redirects.serverPermanentRedirect({
64
+ localePrefix: config$1.localePrefix,
69
65
  pathname
70
66
  }, ...args);
71
67
  }
72
- function getPathname(_ref3) {
68
+ function getPathname(_ref2) {
73
69
  let {
74
70
  href,
75
71
  locale
76
- } = _ref3;
72
+ } = _ref2;
77
73
  return utils.compileLocalizedPathname({
78
74
  ...utils.normalizeNameOrNameWithParams(href),
79
75
  locale,
80
- pathnames
76
+ pathnames: config$1.pathnames
81
77
  });
82
78
  }
83
79
  function notSupported(hookName) {
@@ -4,15 +4,16 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
6
  var React = require('react');
7
+ var config = require('../shared/config.js');
7
8
  var ServerLink = require('./ServerLink.js');
8
- var serverPermanentRedirect = require('./serverPermanentRedirect.js');
9
- var serverRedirect = require('./serverRedirect.js');
9
+ var redirects = require('./redirects.js');
10
10
 
11
11
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
12
 
13
13
  var React__default = /*#__PURE__*/_interopDefault(React);
14
14
 
15
- function createSharedPathnamesNavigation(opts) {
15
+ function createSharedPathnamesNavigation(input) {
16
+ const config$1 = config.receiveSharedNavigationRoutingConfig(input);
16
17
  function notSupported(hookName) {
17
18
  return () => {
18
19
  throw new Error("`".concat(hookName, "` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."));
@@ -20,25 +21,25 @@ function createSharedPathnamesNavigation(opts) {
20
21
  }
21
22
  function Link(props) {
22
23
  return /*#__PURE__*/React__default.default.createElement(ServerLink.default, _rollupPluginBabelHelpers.extends({
23
- localePrefix: opts === null || opts === void 0 ? void 0 : opts.localePrefix
24
+ localePrefix: config$1.localePrefix
24
25
  }, props));
25
26
  }
26
27
  function redirect(pathname) {
27
28
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
28
29
  args[_key - 1] = arguments[_key];
29
30
  }
30
- return serverRedirect.default({
31
- ...opts,
32
- pathname
31
+ return redirects.serverRedirect({
32
+ pathname,
33
+ localePrefix: config$1.localePrefix
33
34
  }, ...args);
34
35
  }
35
36
  function permanentRedirect(pathname) {
36
37
  for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
37
38
  args[_key2 - 1] = arguments[_key2];
38
39
  }
39
- return serverPermanentRedirect.default({
40
- ...opts,
41
- pathname
40
+ return redirects.serverPermanentRedirect({
41
+ pathname,
42
+ localePrefix: config$1.localePrefix
42
43
  }, ...args);
43
44
  }
44
45
  return {
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var RequestLocale = require('../../server/react-server/RequestLocale.js');
6
+ var redirects = require('../shared/redirects.js');
7
+
8
+ function createRedirectFn(redirectFn) {
9
+ return function serverRedirect(params) {
10
+ const locale = RequestLocale.getRequestLocale();
11
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
12
+ args[_key - 1] = arguments[_key];
13
+ }
14
+ return redirectFn({
15
+ ...params,
16
+ locale
17
+ }, ...args);
18
+ };
19
+ }
20
+ const serverRedirect = createRedirectFn(redirects.baseRedirect);
21
+ const serverPermanentRedirect = createRedirectFn(redirects.basePermanentRedirect);
22
+
23
+ exports.serverPermanentRedirect = serverPermanentRedirect;
24
+ exports.serverRedirect = serverRedirect;
@@ -20,9 +20,10 @@ function BaseLink(_ref, ref) {
20
20
  let {
21
21
  href,
22
22
  locale,
23
- localePrefix,
23
+ localePrefixMode,
24
24
  onClick,
25
25
  prefetch,
26
+ prefix,
26
27
  ...rest
27
28
  } = _ref;
28
29
  // The types aren't entirely correct here. Outside of Next.js
@@ -30,7 +31,7 @@ function BaseLink(_ref, ref) {
30
31
  const pathname = navigation.usePathname();
31
32
  const curLocale = useLocale.default();
32
33
  const isChangingLocale = locale !== curLocale;
33
- const [localizedHref, setLocalizedHref] = React.useState(() => utils.isLocalHref(href) && (localePrefix !== 'never' || isChangingLocale) ?
34
+ const [localizedHref, setLocalizedHref] = React.useState(() => utils.isLocalizableHref(href) && (localePrefixMode !== 'never' || isChangingLocale) ?
34
35
  // For the `localePrefix: 'as-needed' strategy, the href shouldn't
35
36
  // be prefixed if the locale is the default locale. To determine this, we
36
37
  // need a) the default locale and b) the information if we use prefixed
@@ -41,15 +42,15 @@ function BaseLink(_ref, ref) {
41
42
  // is better than pointing to a non-localized href during the server
42
43
  // render, which would potentially be wrong. The final href is
43
44
  // determined in the effect below.
44
- utils.prefixHref(href, locale) : href);
45
+ utils.prefixHref(href, prefix) : href);
45
46
  function onLinkClick(event) {
46
47
  syncLocaleCookie.default(pathname, curLocale, locale);
47
48
  if (onClick) onClick(event);
48
49
  }
49
50
  React.useEffect(() => {
50
51
  if (!pathname) return;
51
- setLocalizedHref(utils.localizeHref(href, locale, curLocale, pathname));
52
- }, [curLocale, href, locale, pathname]);
52
+ setLocalizedHref(utils.localizeHref(href, locale, curLocale, pathname, prefix));
53
+ }, [curLocale, href, locale, pathname, prefix]);
53
54
  if (isChangingLocale) {
54
55
  if (prefetch && "development" !== 'production') {
55
56
  console.error('The `prefetch` prop is currently not supported when using the `locale` prop on `Link` to switch the locale.`');
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var config = require('../../routing/config.js');
6
+
7
+ /**
8
+ * Shared pathnames
9
+ */
10
+
11
+ function receiveSharedNavigationRoutingConfig(input) {
12
+ return {
13
+ ...input,
14
+ localePrefix: config.receiveLocalePrefixConfig(input === null || input === void 0 ? void 0 : input.localePrefix)
15
+ };
16
+ }
17
+
18
+ /**
19
+ * Localized pathnames
20
+ */
21
+
22
+ function receiveLocalizedNavigationRoutingConfig(input) {
23
+ return {
24
+ ...input,
25
+ localePrefix: config.receiveLocalePrefixConfig(input === null || input === void 0 ? void 0 : input.localePrefix)
26
+ };
27
+ }
28
+
29
+ exports.receiveLocalizedNavigationRoutingConfig = receiveLocalizedNavigationRoutingConfig;
30
+ exports.receiveSharedNavigationRoutingConfig = receiveSharedNavigationRoutingConfig;
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var navigation = require('next/navigation');
6
+ var utils = require('../../shared/utils.js');
7
+
8
+ function createRedirectFn(redirectFn) {
9
+ return function baseRedirect(params) {
10
+ const prefix = utils.getLocalePrefix(params.locale, params.localePrefix);
11
+ const localizedPathname = params.localePrefix.mode === 'never' || !utils.isLocalHref(params.pathname) ? params.pathname : utils.prefixPathname(prefix, params.pathname);
12
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
13
+ args[_key - 1] = arguments[_key];
14
+ }
15
+ return redirectFn(localizedPathname, ...args);
16
+ };
17
+ }
18
+ const baseRedirect = createRedirectFn(navigation.redirect);
19
+ const basePermanentRedirect = createRedirectFn(navigation.permanentRedirect);
20
+
21
+ exports.basePermanentRedirect = basePermanentRedirect;
22
+ exports.baseRedirect = baseRedirect;
@@ -90,13 +90,11 @@ function getRoute(_ref3) {
90
90
  pathname,
91
91
  pathnames
92
92
  } = _ref3;
93
- const unlocalizedPathname = utils.unlocalizePathname(
94
- // Potentially handle foreign symbols
95
- decodeURI(pathname), locale);
93
+ const decoded = decodeURI(pathname);
96
94
  let template = (_Object$entries$find = Object.entries(pathnames).find(_ref4 => {
97
95
  let [, routePath] = _ref4;
98
96
  const routePathname = typeof routePath !== 'string' ? routePath[locale] : routePath;
99
- return utils.matchesPathname(routePathname, unlocalizedPathname);
97
+ return utils.matchesPathname(routePathname, decoded);
100
98
  })) === null || _Object$entries$find === void 0 ? void 0 : _Object$entries$find[0];
101
99
  if (!template) {
102
100
  template = pathname;
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /**
6
+ * Maintainer note: The config that is accepted by the middleware, the shared
7
+ * and the localized pathnames navigation factory function is slightly
8
+ * different. This type declares the shared base config that is accepted by all
9
+ * of them. Properties that are different are declared in consuming types.
10
+ */
11
+
12
+ function receiveLocalePrefixConfig(localePrefix) {
13
+ return typeof localePrefix === 'object' ? localePrefix : {
14
+ mode: localePrefix || 'always'
15
+ };
16
+ }
17
+
18
+ exports.receiveLocalePrefixConfig = receiveLocalePrefixConfig;
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -13,7 +13,7 @@ function getLocaleFromHeaderImpl() {
13
13
  locale = headers.headers().get(constants.HEADER_LOCALE_NAME);
14
14
  } catch (error) {
15
15
  if (error instanceof Error && error.digest === 'DYNAMIC_SERVER_USAGE') {
16
- throw new Error('Usage of next-intl APIs in Server Components currently opts into dynamic rendering. This limitation will eventually be lifted, but as a stopgap solution, you can use the `unstable_setRequestLocale` API to enable static rendering, see https://next-intl-docs.vercel.app/docs/getting-started/app-router-server-components#static-rendering', {
16
+ throw new Error('Usage of next-intl APIs in Server Components currently opts into dynamic rendering. This limitation will eventually be lifted, but as a stopgap solution, you can use the `unstable_setRequestLocale` API to enable static rendering, see https://next-intl-docs.vercel.app/docs/getting-started/app-router/with-i18n-routing#static-rendering', {
17
17
  cause: error
18
18
  });
19
19
  } else {
@@ -14,39 +14,43 @@ function isLocalHref(href) {
14
14
  return !hasProtocol;
15
15
  }
16
16
  }
17
+ function isLocalizableHref(href) {
18
+ return isLocalHref(href) && !isRelativeHref(href);
19
+ }
17
20
  function localizeHref(href, locale) {
18
21
  let curLocale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : locale;
19
22
  let curPathname = arguments.length > 3 ? arguments[3] : undefined;
20
- if (!isLocalHref(href) || isRelativeHref(href)) {
23
+ let prefix = arguments.length > 4 ? arguments[4] : undefined;
24
+ if (!isLocalizableHref(href)) {
21
25
  return href;
22
26
  }
23
27
  const isSwitchingLocale = locale !== curLocale;
24
- const isPathnamePrefixed = locale == null || hasPathnamePrefixed(locale, curPathname);
28
+ const isPathnamePrefixed = hasPathnamePrefixed(prefix, curPathname);
25
29
  const shouldPrefix = isSwitchingLocale || isPathnamePrefixed;
26
- if (shouldPrefix && locale != null) {
27
- return prefixHref(href, locale);
30
+ if (shouldPrefix && prefix != null) {
31
+ return prefixHref(href, prefix);
28
32
  }
29
33
  return href;
30
34
  }
31
- function prefixHref(href, locale) {
35
+ function prefixHref(href, prefix) {
32
36
  let prefixedHref;
33
37
  if (typeof href === 'string') {
34
- prefixedHref = prefixPathname(locale, href);
38
+ prefixedHref = prefixPathname(prefix, href);
35
39
  } else {
36
40
  prefixedHref = {
37
41
  ...href
38
42
  };
39
43
  if (href.pathname) {
40
- prefixedHref.pathname = prefixPathname(locale, href.pathname);
44
+ prefixedHref.pathname = prefixPathname(prefix, href.pathname);
41
45
  }
42
46
  }
43
47
  return prefixedHref;
44
48
  }
45
- function unlocalizePathname(pathname, locale) {
46
- return pathname.replace(new RegExp("^/".concat(locale)), '') || '/';
49
+ function unprefixPathname(pathname, prefix) {
50
+ return pathname.replace(new RegExp("^".concat(prefix)), '') || '/';
47
51
  }
48
- function prefixPathname(locale, pathname) {
49
- let localizedHref = '/' + locale;
52
+ function prefixPathname(prefix, pathname) {
53
+ let localizedHref = prefix;
50
54
 
51
55
  // Avoid trailing slashes
52
56
  if (/^\/(\?.*)?$/.test(pathname)) {
@@ -55,8 +59,7 @@ function prefixPathname(locale, pathname) {
55
59
  localizedHref += pathname;
56
60
  return localizedHref;
57
61
  }
58
- function hasPathnamePrefixed(locale, pathname) {
59
- const prefix = "/".concat(locale);
62
+ function hasPathnamePrefixed(prefix, pathname) {
60
63
  return pathname === prefix || pathname.startsWith("".concat(prefix, "/"));
61
64
  }
62
65
  function matchesPathname( /** E.g. `/users/[userId]-[userName]` */
@@ -65,6 +68,13 @@ pathname) {
65
68
  const regex = templateToRegex(template);
66
69
  return regex.test(pathname);
67
70
  }
71
+ function getLocalePrefix(locale, localePrefix) {
72
+ var _localePrefix$prefixe;
73
+ return localePrefix.mode !== 'never' && ((_localePrefix$prefixe = localePrefix.prefixes) === null || _localePrefix$prefixe === void 0 ? void 0 : _localePrefix$prefixe[locale]) ||
74
+ // We return a prefix even if `mode: 'never'`. It's up to the consumer
75
+ // to decide to use it or not.
76
+ '/' + locale;
77
+ }
68
78
  function templateToRegex(template) {
69
79
  const regexPattern = template
70
80
  // Replace optional catchall ('[[...slug]]')
@@ -76,12 +86,14 @@ function templateToRegex(template) {
76
86
  return new RegExp("^".concat(regexPattern, "$"));
77
87
  }
78
88
 
89
+ exports.getLocalePrefix = getLocalePrefix;
79
90
  exports.hasPathnamePrefixed = hasPathnamePrefixed;
80
91
  exports.isLocalHref = isLocalHref;
92
+ exports.isLocalizableHref = isLocalizableHref;
81
93
  exports.isRelativeHref = isRelativeHref;
82
94
  exports.localizeHref = localizeHref;
83
95
  exports.matchesPathname = matchesPathname;
84
96
  exports.prefixHref = prefixHref;
85
97
  exports.prefixPathname = prefixPathname;
86
98
  exports.templateToRegex = templateToRegex;
87
- exports.unlocalizePathname = unlocalizePathname;
99
+ exports.unprefixPathname = unprefixPathname;
@@ -1 +1 @@
1
- function t(){throw new Error("Couldn't find next-intl config file. Please follow the instructions at https://next-intl-docs.vercel.app/docs/getting-started/app-router-server-components")}export{t as default};
1
+ function t(){throw new Error("Couldn't find next-intl config file. Please follow the instructions at https://next-intl-docs.vercel.app/docs/getting-started/app-router")}export{t as default};
@@ -0,0 +1 @@
1
+ import{receiveLocalePrefixConfig as l}from"../routing/config.js";function o(o){var e,n;return{...o,alternateLinks:null===(e=null==o?void 0:o.alternateLinks)||void 0===e||e,localeDetection:null===(n=null==o?void 0:o.localeDetection)||void 0===n||n,localePrefix:l(null==o?void 0:o.localePrefix)}}export{o as receiveConfig};
@@ -1 +1 @@
1
- import{getHost as a,getNormalizedPathname as e,isLocaleSupportedOnDomain as t,applyBasePath as n,formatTemplatePathname as o}from"./utils.js";function l(l){var r;let{config:c,localizedPathnames:p,request:s,resolvedLocale:f}=l;const h=s.nextUrl.clone(),i=a(s.headers);function m(a,e){return s.nextUrl.basePath&&((a=new URL(a)).pathname=n(a.pathname,s.nextUrl.basePath)),"<".concat(a.toString(),'>; rel="alternate"; hreflang="').concat(e,'"')}function u(a,e){return p&&"object"==typeof p?o(a,p[f],p[e]):a}i&&(h.port="",h.host=i),h.protocol=null!==(r=s.headers.get("x-forwarded-proto"))&&void 0!==r?r:h.protocol,h.pathname=e(h.pathname,c.locales);const d=c.locales.flatMap((a=>{function e(e){return"/"===e?"/".concat(a):"/".concat(a).concat(e)}let n;if(c.domains){return(c.domains.filter((e=>t(a,e)))||[]).map((t=>(n=new URL(h),n.port="",n.host=t.domain,n.pathname=u(h.pathname,a),a===t.defaultLocale&&"always"!==c.localePrefix||(n.pathname=e(n.pathname)),m(n,a))))}{let t;t=p&&"object"==typeof p?u(h.pathname,a):h.pathname,a===c.defaultLocale&&"always"!==c.localePrefix||(t=e(t)),n=new URL(t,h)}return m(n,a)}));if(!c.domains&&("always"!==c.localePrefix||"/"===h.pathname)){const a=new URL(u(h.pathname,c.defaultLocale),h);d.push(m(a,"x-default"))}return d.join(", ")}export{l as default};
1
+ import{getHost as e,getNormalizedPathname as a,getLocalePrefixes as t,isLocaleSupportedOnDomain as o,applyBasePath as n,formatTemplatePathname as l}from"./utils.js";function r(r){var c;let{config:f,localizedPathnames:p,request:s,resolvedLocale:i}=r;const m=s.nextUrl.clone(),h=e(s.headers);function d(e,a){return s.nextUrl.basePath&&((e=new URL(e)).pathname=n(e.pathname,s.nextUrl.basePath)),"<".concat(e.toString(),'>; rel="alternate"; hreflang="').concat(a,'"')}function u(e,a){return p&&"object"==typeof p?l(e,p[i],p[a]):e}h&&(m.port="",m.host=h),m.protocol=null!==(c=s.headers.get("x-forwarded-proto"))&&void 0!==c?c:m.protocol,m.pathname=a(m.pathname,f.locales,f.localePrefix);const x=t(f.locales,f.localePrefix).flatMap((e=>{let a,[t,n]=e;function l(e){return"/"===e?n:n+e}if(f.domains){return(f.domains.filter((e=>o(t,e)))||[]).map((e=>(a=new URL(m),a.port="",a.host=e.domain,a.pathname=u(m.pathname,t),t===e.defaultLocale&&"always"!==f.localePrefix.mode||(a.pathname=l(a.pathname)),d(a,t))))}{let e;e=p&&"object"==typeof p?u(m.pathname,t):m.pathname,t===f.defaultLocale&&"always"!==f.localePrefix.mode||(e=l(e)),a=new URL(e,m)}return d(a,t)}));if(!f.domains&&("always"!==f.localePrefix.mode||"/"===m.pathname)){const e=new URL(u(m.pathname,f.defaultLocale),m);x.push(d(e,"x-default"))}return x.join(", ")}export{r as default};
@@ -1 +1 @@
1
- import{NextResponse as e}from"next/server";import{COOKIE_LOCALE_NAME as t,COOKIE_SAME_SITE as a,COOKIE_MAX_AGE as o,HEADER_LOCALE_NAME as n}from"../shared/constants.js";import{matchesPathname as l}from"../shared/utils.js";import r from"./getAlternateLinksHeaderValue.js";import s from"./resolveLocale.js";import{isLocaleSupportedOnDomain as i,getNormalizedPathname as c,getPathnameLocale as d,getInternalTemplate as f,formatTemplatePathname as u,getPathWithSearch as h,getBestMatchingDomain as m,applyBasePath as v}from"./utils.js";function x(x){const p=function(e){var t,a,o;return{...e,alternateLinks:null===(t=e.alternateLinks)||void 0===t||t,localePrefix:null!==(a=e.localePrefix)&&void 0!==a?a:"always",localeDetection:null===(o=e.localeDetection)||void 0===o||o}}(x);return function(x){var P,U;const g=decodeURI(x.nextUrl.pathname),{domain:L,locale:k}=s(p,x.headers,x.cookies,g),w=p.localeDetection&&(null===(P=x.cookies.get(t))||void 0===P?void 0:P.value)!==k,b=L?L.defaultLocale===k:k===p.defaultLocale,j=(null===(U=p.domains)||void 0===U?void 0:U.filter((e=>i(k,e))))||[],y=null!=p.domains&&!L;function D(t){const a=new URL(t,x.url);return x.nextUrl.basePath&&(a.pathname=v(a.pathname,x.nextUrl.basePath)),e.rewrite(a,function(){const e=new Headers(x.headers);return e.set(n,k),{request:{headers:e}}}())}function R(t,a){const o=new URL(t,x.url);if(j.length>0&&!a){const e=m(L,k,j);e&&(a=e.domain,e.defaultLocale===k&&"as-needed"===p.localePrefix&&o.pathname.startsWith("/".concat(k))&&(o.pathname=c(o.pathname,p.locales)))}var n,l;a&&(o.host=a,x.headers.get("x-forwarded-host")&&(o.protocol=null!==(n=x.headers.get("x-forwarded-proto"))&&void 0!==n?n:x.nextUrl.protocol,o.port=null!==(l=x.headers.get("x-forwarded-port"))&&void 0!==l?l:""));return x.nextUrl.basePath&&(o.pathname=v(o.pathname,x.nextUrl.basePath)),e.redirect(o.toString())}const q=c(g,p.locales),A=d(g,p.locales),H=null!=A;let S,z,I=g;if(p.pathnames){let e;if([e,z]=f(p.pathnames,q,k),z){const t=p.pathnames[z],a="string"==typeof t?t:t[k];if(l(a,q))I=u(q,a,z,A);else{let o;o=e?"string"==typeof t?t:t[e]:z;const n=!H&&b||"never"===p.localePrefix?void 0:k;S=R(h(u(q,o,a,n),x.nextUrl.search))}}}if(!S)if("/"===I){const e=h("/".concat(k),x.nextUrl.search);S="never"===p.localePrefix||b&&"as-needed"===p.localePrefix?D(e):R(e)}else{const e=h(I,x.nextUrl.search);if(H){const t=h(q,x.nextUrl.search);if("never"===p.localePrefix)S=R(t);else if(A===k)if(b&&"as-needed"===p.localePrefix)S=R(t);else if(p.domains){const a=m(L,A,j);S=(null==L?void 0:L.domain)===(null==a?void 0:a.domain)||y?D(e):R(t,null==a?void 0:a.domain)}else S=D(e);else S=R("/".concat(k).concat(t))}else S="never"===p.localePrefix||b&&("as-needed"===p.localePrefix||p.domains)?D("/".concat(k).concat(e)):R("/".concat(k).concat(e))}var V;(w&&S.cookies.set(t,k,{path:x.nextUrl.basePath||void 0,sameSite:a,maxAge:o}),"never"!==p.localePrefix&&p.alternateLinks&&p.locales.length>1)&&S.headers.set("Link",r({config:p,localizedPathnames:null!=z?null===(V=p.pathnames)||void 0===V?void 0:V[z]:void 0,request:x,resolvedLocale:k}));return S}}export{x as default};
1
+ import{NextResponse as e}from"next/server";import{HEADER_LOCALE_NAME as o}from"../shared/constants.js";import{matchesPathname as l,getLocalePrefix as r}from"../shared/utils.js";import{receiveConfig as t}from"./config.js";import a from"./getAlternateLinksHeaderValue.js";import n from"./resolveLocale.js";import s from"./syncCookie.js";import{isLocaleSupportedOnDomain as i,getNormalizedPathname as c,getPathnameMatch as d,getInternalTemplate as f,formatTemplatePathname as m,formatPathname as h,getBestMatchingDomain as x,applyBasePath as u,normalizeTrailingSlash as p,getLocaleAsPrefix as v}from"./utils.js";function U(U){const P=t(U);return function(t){var U;const g=decodeURI(t.nextUrl.pathname),{domain:L,locale:j}=n(P,t.headers,t.cookies,g),w=L?L.defaultLocale===j:j===P.defaultLocale,k=(null===(U=P.domains)||void 0===U?void 0:U.filter((e=>i(j,e))))||[],b=null!=P.domains&&!L;function y(l){const r=new URL(l,t.url);t.nextUrl.basePath&&(r.pathname=u(r.pathname,t.nextUrl.basePath));const a=new Headers(t.headers);return a.set(o,j),e.rewrite(r,{request:{headers:a}})}function R(o,l){const r=new URL(p(o),t.url);if(k.length>0&&!l){const e=x(L,j,k);e&&(l=e.domain,e.defaultLocale===j&&"as-needed"===P.localePrefix.mode&&(r.pathname=c(r.pathname,P.locales,P.localePrefix)))}var a,n;l&&(r.host=l,t.headers.get("x-forwarded-host")&&(r.protocol=null!==(a=t.headers.get("x-forwarded-proto"))&&void 0!==a?a:t.nextUrl.protocol,r.port=null!==(n=t.headers.get("x-forwarded-port"))&&void 0!==n?n:""));return t.nextUrl.basePath&&(r.pathname=u(r.pathname,t.nextUrl.basePath)),e.redirect(r.toString())}const q=c(g,P.locales,P.localePrefix),H=d(g,P.locales,P.localePrefix),z=null!=H,A="never"===P.localePrefix.mode||w&&"as-needed"===P.localePrefix.mode;let C,D,I=q;if(P.pathnames){let e;if([e,D]=f(P.pathnames,q,j),D){const o=P.pathnames[D],a="string"==typeof o?o:o[j];if(l(a,q))I=m(q,a,D);else{let l;l=e?"string"==typeof o?o:o[e]:D;const n=A?void 0:r(j,P.localePrefix),s=m(q,l,a);C=R(h(s,n,t.nextUrl.search))}}}if(!C)if("/"!==I||z){const e=h(I,v(j),t.nextUrl.search);if(z){const o=h(q,H.prefix,t.nextUrl.search);if("never"===P.localePrefix.mode)C=R(h(q,void 0,t.nextUrl.search));else if(H.exact)if(w&&A)C=R(h(q,void 0,t.nextUrl.search));else if(P.domains){const l=x(L,H.locale,k);C=(null==L?void 0:L.domain)===(null==l?void 0:l.domain)||b?y(e):R(o,null==l?void 0:l.domain)}else C=y(e);else C=R(o)}else C=A?y(e):R(h(q,r(j,P.localePrefix),t.nextUrl.search))}else C=A?y(h(I,v(j),t.nextUrl.search)):R(h(q,r(j,P.localePrefix),t.nextUrl.search));var S;(P.localeDetection&&s(t,C,j),"never"!==P.localePrefix.mode&&P.alternateLinks&&P.locales.length>1)&&C.headers.set("Link",a({config:P,localizedPathnames:null!=D?null===(S=P.pathnames)||void 0===S?void 0:S[D]:void 0,request:t,resolvedLocale:j}));return C}}export{U as default};