next-intl 3.14.1 → 3.15.0-custom-prefixes.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.
- package/dist/development/config.js +1 -1
- package/dist/development/middleware/config.js +17 -0
- package/dist/development/middleware/getAlternateLinksHeaderValue.js +8 -7
- package/dist/development/middleware/middleware.js +56 -61
- package/dist/development/middleware/resolveLocale.js +5 -6
- package/dist/development/middleware/utils.js +58 -30
- package/dist/development/navigation/react-client/ClientLink.js +7 -2
- package/dist/development/navigation/react-client/createLocalizedPathnamesNavigation.js +18 -16
- package/dist/development/navigation/react-client/createSharedPathnamesNavigation.js +17 -12
- package/dist/development/navigation/react-client/redirects.js +32 -0
- package/dist/development/navigation/react-client/useBasePathname.js +12 -4
- package/dist/development/navigation/react-client/useBaseRouter.js +8 -3
- package/dist/development/navigation/react-server/ServerLink.js +7 -1
- package/dist/development/navigation/react-server/createLocalizedPathnamesNavigation.js +15 -19
- package/dist/development/navigation/react-server/createSharedPathnamesNavigation.js +11 -10
- package/dist/development/navigation/react-server/redirects.js +24 -0
- package/dist/development/navigation/shared/BaseLink.js +6 -5
- package/dist/development/navigation/shared/config.js +30 -0
- package/dist/development/navigation/shared/redirects.js +22 -0
- package/dist/development/navigation/shared/utils.js +2 -4
- package/dist/development/routing/config.js +18 -0
- package/dist/development/routing.js +2 -0
- package/dist/development/server/react-server/RequestLocale.js +1 -1
- package/dist/development/shared/utils.js +26 -14
- package/dist/esm/config.js +1 -1
- package/dist/esm/middleware/config.js +1 -0
- package/dist/esm/middleware/getAlternateLinksHeaderValue.js +1 -1
- package/dist/esm/middleware/middleware.js +1 -1
- package/dist/esm/middleware/resolveLocale.js +1 -1
- package/dist/esm/middleware/utils.js +1 -1
- package/dist/esm/navigation/react-client/ClientLink.js +1 -1
- package/dist/esm/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
- package/dist/esm/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
- package/dist/esm/navigation/react-client/redirects.js +1 -0
- package/dist/esm/navigation/react-client/useBasePathname.js +1 -1
- package/dist/esm/navigation/react-client/useBaseRouter.js +1 -1
- package/dist/esm/navigation/react-server/ServerLink.js +1 -1
- package/dist/esm/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -1
- package/dist/esm/navigation/react-server/createSharedPathnamesNavigation.js +1 -1
- package/dist/esm/navigation/react-server/redirects.js +1 -0
- package/dist/esm/navigation/shared/BaseLink.js +1 -1
- package/dist/esm/navigation/shared/config.js +1 -0
- package/dist/esm/navigation/shared/redirects.js +1 -0
- package/dist/esm/navigation/shared/utils.js +1 -1
- package/dist/esm/routing/config.js +1 -0
- package/dist/esm/routing.js +1 -0
- package/dist/esm/server/react-server/RequestLocale.js +1 -1
- package/dist/esm/shared/utils.js +1 -1
- package/dist/production/config.js +1 -1
- package/dist/production/middleware/config.js +1 -0
- package/dist/production/middleware/getAlternateLinksHeaderValue.js +1 -1
- package/dist/production/middleware/middleware.js +1 -1
- package/dist/production/middleware/resolveLocale.js +1 -1
- package/dist/production/middleware/utils.js +1 -1
- package/dist/production/navigation/react-client/ClientLink.js +1 -1
- package/dist/production/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
- package/dist/production/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
- package/dist/production/navigation/react-client/redirects.js +1 -0
- package/dist/production/navigation/react-client/useBasePathname.js +1 -1
- package/dist/production/navigation/react-client/useBaseRouter.js +1 -1
- package/dist/production/navigation/react-server/ServerLink.js +1 -1
- package/dist/production/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -1
- package/dist/production/navigation/react-server/createSharedPathnamesNavigation.js +1 -1
- package/dist/production/navigation/react-server/redirects.js +1 -0
- package/dist/production/navigation/shared/BaseLink.js +1 -1
- package/dist/production/navigation/shared/config.js +1 -0
- package/dist/production/navigation/shared/redirects.js +1 -0
- package/dist/production/navigation/shared/utils.js +1 -1
- package/dist/production/routing/config.js +1 -0
- package/dist/production/routing.js +1 -0
- package/dist/production/server/react-server/RequestLocale.js +1 -1
- package/dist/production/shared/utils.js +1 -1
- package/dist/routing.js +7 -0
- package/dist/types/src/middleware/config.d.ts +18 -0
- package/dist/types/src/middleware/getAlternateLinksHeaderValue.d.ts +6 -6
- package/dist/types/src/middleware/middleware.d.ts +3 -3
- package/dist/types/src/middleware/resolveLocale.d.ts +6 -6
- package/dist/types/src/middleware/utils.d.ts +19 -12
- package/dist/types/src/navigation/react-client/ClientLink.d.ts +10 -7
- package/dist/types/src/navigation/react-client/createLocalizedPathnamesNavigation.d.ts +21 -22
- package/dist/types/src/navigation/react-client/createSharedPathnamesNavigation.d.ts +22 -10
- package/dist/types/src/navigation/react-client/index.d.ts +3 -1
- package/dist/types/src/navigation/react-client/redirects.d.ts +10 -0
- package/dist/types/src/navigation/react-client/useBasePathname.d.ts +2 -1
- package/dist/types/src/navigation/react-client/useBaseRouter.d.ts +7 -7
- package/dist/types/src/navigation/react-server/ServerLink.d.ts +5 -4
- package/dist/types/src/navigation/react-server/createLocalizedPathnamesNavigation.d.ts +14 -15
- package/dist/types/src/navigation/react-server/createSharedPathnamesNavigation.d.ts +4 -6
- package/dist/types/src/navigation/react-server/index.d.ts +1 -1
- package/dist/types/src/navigation/react-server/redirects.d.ts +10 -0
- package/dist/types/src/navigation/shared/BaseLink.d.ts +3 -2
- package/dist/types/src/navigation/shared/config.d.ts +24 -0
- package/dist/types/src/navigation/shared/redirects.d.ts +11 -0
- package/dist/types/src/navigation/shared/utils.d.ts +10 -10
- package/dist/types/src/routing/config.d.ts +14 -0
- package/dist/types/src/routing/index.d.ts +2 -0
- package/dist/types/src/routing/types.d.ts +23 -0
- package/dist/types/src/routing.d.ts +1 -0
- package/dist/types/src/shared/types.d.ts +0 -5
- package/dist/types/src/shared/utils.d.ts +10 -7
- package/package.json +23 -16
- package/routing.d.ts +1 -0
- package/dist/development/navigation/react-client/clientPermanentRedirect.js +0 -25
- package/dist/development/navigation/react-client/clientRedirect.js +0 -25
- package/dist/development/navigation/react-server/serverPermanentRedirect.js +0 -19
- package/dist/development/navigation/react-server/serverRedirect.js +0 -19
- package/dist/development/navigation/shared/basePermanentRedirect.js +0 -16
- package/dist/development/navigation/shared/baseRedirect.js +0 -16
- package/dist/esm/navigation/react-client/clientPermanentRedirect.js +0 -1
- package/dist/esm/navigation/react-client/clientRedirect.js +0 -1
- package/dist/esm/navigation/react-server/serverPermanentRedirect.js +0 -1
- package/dist/esm/navigation/react-server/serverRedirect.js +0 -1
- package/dist/esm/navigation/shared/basePermanentRedirect.js +0 -1
- package/dist/esm/navigation/shared/baseRedirect.js +0 -1
- package/dist/production/navigation/react-client/clientPermanentRedirect.js +0 -1
- package/dist/production/navigation/react-client/clientRedirect.js +0 -1
- package/dist/production/navigation/react-server/serverPermanentRedirect.js +0 -1
- package/dist/production/navigation/react-server/serverRedirect.js +0 -1
- package/dist/production/navigation/shared/basePermanentRedirect.js +0 -1
- package/dist/production/navigation/shared/baseRedirect.js +0 -1
- package/dist/types/src/middleware/NextIntlMiddlewareConfig.d.ts +0 -31
- package/dist/types/src/navigation/react-client/clientPermanentRedirect.d.ts +0 -6
- package/dist/types/src/navigation/react-client/clientRedirect.d.ts +0 -6
- package/dist/types/src/navigation/react-server/serverPermanentRedirect.d.ts +0 -6
- package/dist/types/src/navigation/react-server/serverRedirect.d.ts +0 -6
- package/dist/types/src/navigation/shared/basePermanentRedirect.d.ts +0 -7
- package/dist/types/src/navigation/shared/baseRedirect.d.ts +0 -7
- /package/dist/types/test/navigation/shared/{basePermanentRedirect.test.d.ts → redirects.test.d.ts} +0 -0
- /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
|
|
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(
|
|
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:
|
|
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
|
|
31
|
-
|
|
32
|
-
|
|
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
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
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
|
|
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
|
|
32
|
-
const
|
|
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
|
-
|
|
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:
|
|
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
|
|
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(
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
} =
|
|
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
|
|
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
|
|
68
|
-
localePrefix,
|
|
63
|
+
return redirects.serverPermanentRedirect({
|
|
64
|
+
localePrefix: config$1.localePrefix,
|
|
69
65
|
pathname
|
|
70
66
|
}, ...args);
|
|
71
67
|
}
|
|
72
|
-
function getPathname(
|
|
68
|
+
function getPathname(_ref2) {
|
|
73
69
|
let {
|
|
74
70
|
href,
|
|
75
71
|
locale
|
|
76
|
-
} =
|
|
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
|
|
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(
|
|
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:
|
|
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
|
|
31
|
-
|
|
32
|
-
|
|
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
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
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.
|
|
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,
|
|
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
|
|
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,
|
|
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;
|
|
@@ -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-
|
|
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
|
-
|
|
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 =
|
|
28
|
+
const isPathnamePrefixed = hasPathnamePrefixed(prefix, curPathname);
|
|
25
29
|
const shouldPrefix = isSwitchingLocale || isPathnamePrefixed;
|
|
26
|
-
if (shouldPrefix &&
|
|
27
|
-
return prefixHref(href,
|
|
30
|
+
if (shouldPrefix && prefix != null) {
|
|
31
|
+
return prefixHref(href, prefix);
|
|
28
32
|
}
|
|
29
33
|
return href;
|
|
30
34
|
}
|
|
31
|
-
function prefixHref(href,
|
|
35
|
+
function prefixHref(href, prefix) {
|
|
32
36
|
let prefixedHref;
|
|
33
37
|
if (typeof href === 'string') {
|
|
34
|
-
prefixedHref = prefixPathname(
|
|
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(
|
|
44
|
+
prefixedHref.pathname = prefixPathname(prefix, href.pathname);
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
47
|
return prefixedHref;
|
|
44
48
|
}
|
|
45
|
-
function
|
|
46
|
-
return pathname.replace(new RegExp("
|
|
49
|
+
function unprefixPathname(pathname, prefix) {
|
|
50
|
+
return pathname.replace(new RegExp("^".concat(prefix)), '') || '/';
|
|
47
51
|
}
|
|
48
|
-
function prefixPathname(
|
|
49
|
-
let localizedHref =
|
|
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(
|
|
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.
|
|
99
|
+
exports.unprefixPathname = unprefixPathname;
|
package/dist/esm/config.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
1
|
+
import{NextResponse as e}from"next/server";import{COOKIE_LOCALE_NAME as o,COOKIE_SAME_SITE as t,COOKIE_MAX_AGE as a,HEADER_LOCALE_NAME as l}from"../shared/constants.js";import{matchesPathname as r,getLocalePrefix as n}from"../shared/utils.js";import{receiveConfig as s}from"./config.js";import i from"./getAlternateLinksHeaderValue.js";import c from"./resolveLocale.js";import{isLocaleSupportedOnDomain as d,getNormalizedPathname as f,getPathnameMatch as m,getInternalTemplate as h,formatTemplatePathname as x,formatPathname as u,getBestMatchingDomain as p,applyBasePath as v,normalizeTrailingSlash as P,getLocaleAsPrefix as U}from"./utils.js";function g(g){const L=s(g);return function(s){var g,w;const j=decodeURI(s.nextUrl.pathname),{domain:k,locale:b}=c(L,s.headers,s.cookies,j),R=L.localeDetection&&(null===(g=s.cookies.get(o))||void 0===g?void 0:g.value)!==b,q=k?k.defaultLocale===b:b===L.defaultLocale,y=(null===(w=L.domains)||void 0===w?void 0:w.filter((e=>d(b,e))))||[],A=null!=L.domains&&!k;function H(o){const t=new URL(o,s.url);return s.nextUrl.basePath&&(t.pathname=v(t.pathname,s.nextUrl.basePath)),e.rewrite(t,function(){const e=new Headers(s.headers);return e.set(l,b),{request:{headers:e}}}())}function S(o,t){const a=new URL(P(o),s.url);if(y.length>0&&!t){const e=p(k,b,y);e&&(t=e.domain,e.defaultLocale===b&&"as-needed"===L.localePrefix.mode&&a.pathname.startsWith(n(b,L.localePrefix))&&(a.pathname=f(a.pathname,L.locales,L.localePrefix)))}var l,r;t&&(a.host=t,s.headers.get("x-forwarded-host")&&(a.protocol=null!==(l=s.headers.get("x-forwarded-proto"))&&void 0!==l?l:s.nextUrl.protocol,a.port=null!==(r=s.headers.get("x-forwarded-port"))&&void 0!==r?r:""));return s.nextUrl.basePath&&(a.pathname=v(a.pathname,s.nextUrl.basePath)),e.redirect(a.toString())}const z=f(j,L.locales,L.localePrefix),D=m(j,L.locales,L.localePrefix),I=null!=D,V="never"===L.localePrefix.mode||q&&"as-needed"===L.localePrefix.mode;let W,B,C=z;if(L.pathnames){let e;if([e,B]=h(L.pathnames,z,b),B){const o=L.pathnames[B],t="string"==typeof o?o:o[b];if(r(t,z))C=x(z,t,B);else{let a;a=e?"string"==typeof o?o:o[e]:B;const l=V?void 0:n(b,L.localePrefix),r=x(z,a,t);W=S(u(r,l,s.nextUrl.search))}}}if(!W)if("/"!==C||I){const e=u(C,U(b),s.nextUrl.search);if(I){const o=u(z,D.prefix,s.nextUrl.search);if("never"===L.localePrefix.mode)W=S(u(z,void 0,s.nextUrl.search));else if(D.exact)if(q&&V)W=S(u(z,void 0,s.nextUrl.search));else if(L.domains){const t=p(k,D.locale,y);W=(null==k?void 0:k.domain)===(null==t?void 0:t.domain)||A?H(e):S(o,null==t?void 0:t.domain)}else W=H(e);else W=S(o)}else W=V?H(e):S(u(z,n(b,L.localePrefix),s.nextUrl.search))}else W=V?H(u(C,U(b),s.nextUrl.search)):S(u(z,n(b,L.localePrefix),s.nextUrl.search));var E;(R&&W.cookies.set(o,b,{path:s.nextUrl.basePath||void 0,sameSite:t,maxAge:a}),"never"!==L.localePrefix.mode&&L.alternateLinks&&L.locales.length>1)&&W.headers.set("Link",i({config:L,localizedPathnames:null!=B?null===(E=L.pathnames)||void 0===E?void 0:E[B]:void 0,request:s,resolvedLocale:b}));return W}}export{g as default};
|