next-intl 3.1.4-alpha.1 → 3.2.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/middleware/middleware.js +6 -6
- package/dist/development/navigation/react-client/{BaseLink.js → ClientLink.js} +7 -7
- package/dist/development/navigation/react-client/{baseRedirect.js → clientRedirect.js} +7 -4
- package/dist/development/navigation/react-client/createLocalizedPathnamesNavigation.js +18 -18
- package/dist/development/navigation/react-client/createSharedPathnamesNavigation.js +27 -4
- package/dist/development/navigation/react-server/{BaseLink.js → ServerLink.js} +4 -4
- package/dist/development/navigation/react-server/createLocalizedPathnamesNavigation.js +11 -6
- package/dist/development/navigation/react-server/createSharedPathnamesNavigation.js +24 -4
- package/dist/development/navigation/react-server/{baseRedirect.js → serverRedirect.js} +7 -4
- package/dist/development/{shared/BaseLinkWithLocale.js → navigation/shared/BaseLink.js} +21 -16
- package/dist/development/navigation/shared/baseRedirect.js +16 -0
- package/dist/development/shared/utils.js +7 -7
- package/dist/esm/middleware/middleware.js +1 -1
- package/dist/esm/navigation/react-client/ClientLink.js +1 -0
- package/dist/esm/navigation/react-client/clientRedirect.js +1 -0
- 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-server/ServerLink.js +1 -0
- 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/serverRedirect.js +1 -0
- package/dist/esm/navigation/shared/BaseLink.js +2 -0
- package/dist/esm/navigation/shared/baseRedirect.js +1 -0
- package/dist/esm/shared/utils.js +1 -1
- package/dist/production/middleware/middleware.js +1 -1
- package/dist/production/navigation/react-client/ClientLink.js +1 -0
- package/dist/production/navigation/react-client/clientRedirect.js +1 -0
- 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-server/ServerLink.js +1 -0
- 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/serverRedirect.js +1 -0
- package/dist/production/navigation/shared/BaseLink.js +2 -0
- package/dist/production/navigation/shared/baseRedirect.js +1 -0
- package/dist/production/shared/utils.js +1 -1
- package/dist/types/src/middleware/NextIntlMiddlewareConfig.d.ts +1 -2
- package/dist/types/src/navigation/react-client/{BaseLink.d.ts → ClientLink.d.ts} +5 -4
- package/dist/types/src/navigation/react-client/clientRedirect.d.ts +6 -0
- package/dist/types/src/navigation/react-client/createLocalizedPathnamesNavigation.d.ts +7 -5
- package/dist/types/src/navigation/react-client/createSharedPathnamesNavigation.d.ts +43 -5
- package/dist/types/src/navigation/react-server/ServerLink.d.ts +8 -0
- package/dist/types/src/navigation/react-server/createLocalizedPathnamesNavigation.d.ts +5 -3
- package/dist/types/src/navigation/react-server/createSharedPathnamesNavigation.d.ts +6 -38
- package/dist/types/src/navigation/react-server/serverRedirect.d.ts +6 -0
- package/dist/types/src/navigation/shared/BaseLink.d.ts +9 -0
- package/dist/types/src/navigation/shared/baseRedirect.d.ts +7 -0
- package/dist/types/src/shared/types.d.ts +1 -0
- package/dist/types/src/shared/utils.d.ts +3 -3
- package/dist/types/test/navigation/createSharedPathnamesNavigation.test.d.ts +1 -0
- package/dist/types/test/navigation/react-client/ClientLink.test.d.ts +1 -0
- package/package.json +18 -14
- package/dist/development/shared/redirectWithLocale.js +0 -16
- package/dist/esm/navigation/react-client/BaseLink.js +0 -1
- package/dist/esm/navigation/react-client/baseRedirect.js +0 -1
- package/dist/esm/navigation/react-server/BaseLink.js +0 -1
- package/dist/esm/navigation/react-server/baseRedirect.js +0 -1
- package/dist/esm/shared/BaseLinkWithLocale.js +0 -2
- package/dist/esm/shared/redirectWithLocale.js +0 -1
- package/dist/production/navigation/react-client/BaseLink.js +0 -1
- package/dist/production/navigation/react-client/baseRedirect.js +0 -1
- package/dist/production/navigation/react-server/BaseLink.js +0 -1
- package/dist/production/navigation/react-server/baseRedirect.js +0 -1
- package/dist/production/shared/BaseLinkWithLocale.js +0 -2
- package/dist/production/shared/redirectWithLocale.js +0 -1
- package/dist/types/src/navigation/react-client/baseRedirect.d.ts +0 -3
- package/dist/types/src/navigation/react-server/BaseLink.d.ts +0 -8
- package/dist/types/src/navigation/react-server/baseRedirect.d.ts +0 -3
- package/dist/types/src/shared/BaseLinkWithLocale.d.ts +0 -7
- package/dist/types/src/shared/redirectWithLocale.d.ts +0 -3
- /package/dist/types/test/navigation/{react-client/BaseLink.test.d.ts → createLocalizedPathnamesNavigation.test.d.ts} +0 -0
|
@@ -94,9 +94,9 @@ function createMiddleware(config) {
|
|
|
94
94
|
response = redirect(pathWithSearch);
|
|
95
95
|
}
|
|
96
96
|
} else {
|
|
97
|
-
const
|
|
97
|
+
const internalPathWithSearch = utils.getPathWithSearch(pathname, request.nextUrl.search);
|
|
98
98
|
if (hasLocalePrefix) {
|
|
99
|
-
const basePath = utils.getBasePath(
|
|
99
|
+
const basePath = utils.getBasePath(utils.getPathWithSearch(normalizedPathname, request.nextUrl.search), pathLocale);
|
|
100
100
|
if (configWithDefaults.localePrefix === 'never') {
|
|
101
101
|
response = redirect(basePath);
|
|
102
102
|
} else if (pathLocale === locale) {
|
|
@@ -108,10 +108,10 @@ function createMiddleware(config) {
|
|
|
108
108
|
if ((domain === null || domain === void 0 ? void 0 : domain.domain) !== (pathDomain === null || pathDomain === void 0 ? void 0 : pathDomain.domain) && !hasUnknownHost) {
|
|
109
109
|
response = redirect(basePath, pathDomain === null || pathDomain === void 0 ? void 0 : pathDomain.domain);
|
|
110
110
|
} else {
|
|
111
|
-
response = rewrite(
|
|
111
|
+
response = rewrite(internalPathWithSearch);
|
|
112
112
|
}
|
|
113
113
|
} else {
|
|
114
|
-
response = rewrite(
|
|
114
|
+
response = rewrite(internalPathWithSearch);
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
} else {
|
|
@@ -119,9 +119,9 @@ function createMiddleware(config) {
|
|
|
119
119
|
}
|
|
120
120
|
} else {
|
|
121
121
|
if (configWithDefaults.localePrefix === 'never' || hasMatchedDefaultLocale && (configWithDefaults.localePrefix === 'as-needed' || configWithDefaults.domains)) {
|
|
122
|
-
response = rewrite("/".concat(locale).concat(
|
|
122
|
+
response = rewrite("/".concat(locale).concat(internalPathWithSearch));
|
|
123
123
|
} else {
|
|
124
|
-
response = redirect("/".concat(locale).concat(
|
|
124
|
+
response = redirect("/".concat(locale).concat(internalPathWithSearch));
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
}
|
|
@@ -5,20 +5,20 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var useLocale = require('../../react-client/useLocale.js');
|
|
8
|
-
var
|
|
8
|
+
var BaseLink = require('../shared/BaseLink.js');
|
|
9
9
|
|
|
10
10
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
|
|
12
12
|
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
13
13
|
|
|
14
|
-
function
|
|
14
|
+
function ClientLink(_ref, ref) {
|
|
15
15
|
let {
|
|
16
16
|
locale,
|
|
17
17
|
...rest
|
|
18
18
|
} = _ref;
|
|
19
19
|
const defaultLocale = useLocale.default();
|
|
20
20
|
const linkLocale = locale || defaultLocale;
|
|
21
|
-
return /*#__PURE__*/React__default.default.createElement(
|
|
21
|
+
return /*#__PURE__*/React__default.default.createElement(BaseLink.default, _rollupPluginBabelHelpers.extends({
|
|
22
22
|
ref: ref,
|
|
23
23
|
hrefLang: linkLocale,
|
|
24
24
|
locale: linkLocale
|
|
@@ -45,8 +45,8 @@ function BaseLink(_ref, ref) {
|
|
|
45
45
|
* the `set-cookie` response header would cause the locale cookie on the current
|
|
46
46
|
* page to be overwritten before the user even decides to change the locale.
|
|
47
47
|
*/
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
var
|
|
48
|
+
const ClientLinkWithRef = /*#__PURE__*/React.forwardRef(ClientLink);
|
|
49
|
+
ClientLinkWithRef.displayName = 'ClientLink';
|
|
50
|
+
var ClientLink$1 = ClientLinkWithRef;
|
|
51
51
|
|
|
52
|
-
exports.default =
|
|
52
|
+
exports.default = ClientLink$1;
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var useLocale = require('../../react-client/useLocale.js');
|
|
6
|
-
var
|
|
6
|
+
var baseRedirect = require('../shared/baseRedirect.js');
|
|
7
7
|
|
|
8
|
-
function
|
|
8
|
+
function clientRedirect(params) {
|
|
9
9
|
let locale;
|
|
10
10
|
try {
|
|
11
11
|
// eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context here is fine, since `redirect` should be called during render
|
|
@@ -16,7 +16,10 @@ function baseRedirect(pathname) {
|
|
|
16
16
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
17
17
|
args[_key - 1] = arguments[_key];
|
|
18
18
|
}
|
|
19
|
-
return
|
|
19
|
+
return baseRedirect.default({
|
|
20
|
+
...params,
|
|
21
|
+
locale
|
|
22
|
+
}, ...args);
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
exports.default =
|
|
25
|
+
exports.default = clientRedirect;
|
|
@@ -6,8 +6,8 @@ var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelper
|
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var useLocale = require('../../react-client/useLocale.js');
|
|
8
8
|
var utils = require('../shared/utils.js');
|
|
9
|
-
var
|
|
10
|
-
var
|
|
9
|
+
var ClientLink = require('./ClientLink.js');
|
|
10
|
+
var clientRedirect = require('./clientRedirect.js');
|
|
11
11
|
var useBasePathname = require('./useBasePathname.js');
|
|
12
12
|
var useBaseRouter = require('./useBaseRouter.js');
|
|
13
13
|
|
|
@@ -15,28 +15,24 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
15
15
|
|
|
16
16
|
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
17
17
|
|
|
18
|
-
function createLocalizedPathnamesNavigation(
|
|
19
|
-
let {
|
|
20
|
-
locales,
|
|
21
|
-
pathnames
|
|
22
|
-
} = _ref;
|
|
18
|
+
function createLocalizedPathnamesNavigation(opts) {
|
|
23
19
|
function useTypedLocale() {
|
|
24
20
|
const locale = useLocale.default();
|
|
25
|
-
const isValid = locales.includes(locale);
|
|
21
|
+
const isValid = opts.locales.includes(locale);
|
|
26
22
|
if (!isValid) {
|
|
27
23
|
throw new Error("Unknown locale encountered: \"".concat(locale, "\". Make sure to validate the locale in `app/[locale]/layout.tsx`.") );
|
|
28
24
|
}
|
|
29
25
|
return locale;
|
|
30
26
|
}
|
|
31
|
-
function Link(
|
|
27
|
+
function Link(_ref, ref) {
|
|
32
28
|
let {
|
|
33
29
|
href,
|
|
34
30
|
locale,
|
|
35
31
|
...rest
|
|
36
|
-
} =
|
|
32
|
+
} = _ref;
|
|
37
33
|
const defaultLocale = useTypedLocale();
|
|
38
34
|
const finalLocale = locale || defaultLocale;
|
|
39
|
-
return /*#__PURE__*/React__default.default.createElement(
|
|
35
|
+
return /*#__PURE__*/React__default.default.createElement(ClientLink.default, _rollupPluginBabelHelpers.extends({
|
|
40
36
|
ref: ref,
|
|
41
37
|
href: utils.compileLocalizedPathname({
|
|
42
38
|
locale: finalLocale,
|
|
@@ -44,9 +40,10 @@ function createLocalizedPathnamesNavigation(_ref) {
|
|
|
44
40
|
pathname: href,
|
|
45
41
|
// @ts-expect-error -- This is ok
|
|
46
42
|
params: typeof href === 'object' ? href.params : undefined,
|
|
47
|
-
pathnames
|
|
43
|
+
pathnames: opts.pathnames
|
|
48
44
|
}),
|
|
49
|
-
locale: locale
|
|
45
|
+
locale: locale,
|
|
46
|
+
localePrefix: opts.localePrefix
|
|
50
47
|
}, rest));
|
|
51
48
|
}
|
|
52
49
|
const LinkWithRef = /*#__PURE__*/React.forwardRef(Link);
|
|
@@ -61,7 +58,10 @@ function createLocalizedPathnamesNavigation(_ref) {
|
|
|
61
58
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
62
59
|
args[_key - 1] = arguments[_key];
|
|
63
60
|
}
|
|
64
|
-
return
|
|
61
|
+
return clientRedirect.default({
|
|
62
|
+
...opts,
|
|
63
|
+
pathname: resolvedHref
|
|
64
|
+
}, ...args);
|
|
65
65
|
}
|
|
66
66
|
function useRouter() {
|
|
67
67
|
const baseRouter = useBaseRouter.default();
|
|
@@ -109,18 +109,18 @@ function createLocalizedPathnamesNavigation(_ref) {
|
|
|
109
109
|
return utils.getRoute({
|
|
110
110
|
pathname,
|
|
111
111
|
locale,
|
|
112
|
-
pathnames
|
|
112
|
+
pathnames: opts.pathnames
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
|
-
function getPathname(
|
|
115
|
+
function getPathname(_ref2) {
|
|
116
116
|
let {
|
|
117
117
|
href,
|
|
118
118
|
locale
|
|
119
|
-
} =
|
|
119
|
+
} = _ref2;
|
|
120
120
|
return utils.compileLocalizedPathname({
|
|
121
121
|
...utils.normalizeNameOrNameWithParams(href),
|
|
122
122
|
locale,
|
|
123
|
-
pathnames
|
|
123
|
+
pathnames: opts.pathnames
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
126
|
return {
|
|
@@ -2,15 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var ClientLink = require('./ClientLink.js');
|
|
8
|
+
var clientRedirect = require('./clientRedirect.js');
|
|
7
9
|
var useBasePathname = require('./useBasePathname.js');
|
|
8
10
|
var useBaseRouter = require('./useBaseRouter.js');
|
|
9
11
|
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
|
|
14
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
15
|
+
|
|
10
16
|
function createSharedPathnamesNavigation(opts) {
|
|
17
|
+
function Link(props, ref) {
|
|
18
|
+
return /*#__PURE__*/React__default.default.createElement(ClientLink.default, _rollupPluginBabelHelpers.extends({
|
|
19
|
+
ref: ref,
|
|
20
|
+
localePrefix: opts.localePrefix
|
|
21
|
+
}, props));
|
|
22
|
+
}
|
|
23
|
+
const LinkWithRef = /*#__PURE__*/React.forwardRef(Link);
|
|
24
|
+
LinkWithRef.displayName = 'Link';
|
|
25
|
+
function redirect(pathname) {
|
|
26
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
27
|
+
args[_key - 1] = arguments[_key];
|
|
28
|
+
}
|
|
29
|
+
return clientRedirect.default({
|
|
30
|
+
...opts,
|
|
31
|
+
pathname
|
|
32
|
+
}, ...args);
|
|
33
|
+
}
|
|
11
34
|
return {
|
|
12
|
-
Link:
|
|
13
|
-
redirect
|
|
35
|
+
Link: LinkWithRef,
|
|
36
|
+
redirect,
|
|
14
37
|
usePathname: useBasePathname.default,
|
|
15
38
|
useRouter: useBaseRouter.default
|
|
16
39
|
};
|
|
@@ -4,21 +4,21 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
|
|
6
6
|
var React = require('react');
|
|
7
|
-
var
|
|
7
|
+
var BaseLink = require('../shared/BaseLink.js');
|
|
8
8
|
var getLocale = require('../../server/getLocale.js');
|
|
9
9
|
|
|
10
10
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
|
|
12
12
|
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
13
13
|
|
|
14
|
-
async function
|
|
14
|
+
async function ServerLink(_ref) {
|
|
15
15
|
let {
|
|
16
16
|
locale,
|
|
17
17
|
...rest
|
|
18
18
|
} = _ref;
|
|
19
|
-
return /*#__PURE__*/React__default.default.createElement(
|
|
19
|
+
return /*#__PURE__*/React__default.default.createElement(BaseLink.default, _rollupPluginBabelHelpers.extends({
|
|
20
20
|
locale: locale || (await getLocale.default())
|
|
21
21
|
}, rest));
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
exports.default =
|
|
24
|
+
exports.default = ServerLink;
|
|
@@ -6,8 +6,8 @@ var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelper
|
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var RequestLocale = require('../../server/RequestLocale.js');
|
|
8
8
|
var utils = require('../shared/utils.js');
|
|
9
|
-
var
|
|
10
|
-
var
|
|
9
|
+
var ServerLink = require('./ServerLink.js');
|
|
10
|
+
var serverRedirect = require('./serverRedirect.js');
|
|
11
11
|
|
|
12
12
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
13
|
|
|
@@ -15,6 +15,7 @@ var React__default = /*#__PURE__*/_interopDefault(React);
|
|
|
15
15
|
|
|
16
16
|
function createLocalizedPathnamesNavigation(_ref) {
|
|
17
17
|
let {
|
|
18
|
+
localePrefix,
|
|
18
19
|
locales,
|
|
19
20
|
pathnames
|
|
20
21
|
} = _ref;
|
|
@@ -26,7 +27,7 @@ function createLocalizedPathnamesNavigation(_ref) {
|
|
|
26
27
|
} = _ref2;
|
|
27
28
|
const defaultLocale = RequestLocale.getRequestLocale();
|
|
28
29
|
const finalLocale = locale || defaultLocale;
|
|
29
|
-
return /*#__PURE__*/React__default.default.createElement(
|
|
30
|
+
return /*#__PURE__*/React__default.default.createElement(ServerLink.default, _rollupPluginBabelHelpers.extends({
|
|
30
31
|
href: utils.compileLocalizedPathname({
|
|
31
32
|
locale: finalLocale,
|
|
32
33
|
// @ts-expect-error -- This is ok
|
|
@@ -35,19 +36,23 @@ function createLocalizedPathnamesNavigation(_ref) {
|
|
|
35
36
|
params: typeof href === 'object' ? href.params : undefined,
|
|
36
37
|
pathnames
|
|
37
38
|
}),
|
|
38
|
-
locale: locale
|
|
39
|
+
locale: locale,
|
|
40
|
+
localePrefix: localePrefix
|
|
39
41
|
}, rest));
|
|
40
42
|
}
|
|
41
43
|
function redirect(href) {
|
|
42
44
|
const locale = RequestLocale.getRequestLocale();
|
|
43
|
-
const
|
|
45
|
+
const pathname = getPathname({
|
|
44
46
|
href,
|
|
45
47
|
locale
|
|
46
48
|
});
|
|
47
49
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
48
50
|
args[_key - 1] = arguments[_key];
|
|
49
51
|
}
|
|
50
|
-
return
|
|
52
|
+
return serverRedirect.default({
|
|
53
|
+
localePrefix,
|
|
54
|
+
pathname
|
|
55
|
+
}, ...args);
|
|
51
56
|
}
|
|
52
57
|
function getPathname(_ref3) {
|
|
53
58
|
let {
|
|
@@ -2,8 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var ServerLink = require('./ServerLink.js');
|
|
8
|
+
var serverRedirect = require('./serverRedirect.js');
|
|
9
|
+
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
7
13
|
|
|
8
14
|
function createSharedPathnamesNavigation(opts) {
|
|
9
15
|
function notSupported(message) {
|
|
@@ -11,9 +17,23 @@ function createSharedPathnamesNavigation(opts) {
|
|
|
11
17
|
throw new Error("`".concat(message, "` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."));
|
|
12
18
|
};
|
|
13
19
|
}
|
|
20
|
+
function Link(props) {
|
|
21
|
+
return /*#__PURE__*/React__default.default.createElement(ServerLink.default, _rollupPluginBabelHelpers.extends({
|
|
22
|
+
localePrefix: opts.localePrefix
|
|
23
|
+
}, props));
|
|
24
|
+
}
|
|
25
|
+
function redirect(pathname) {
|
|
26
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
27
|
+
args[_key - 1] = arguments[_key];
|
|
28
|
+
}
|
|
29
|
+
return serverRedirect.default({
|
|
30
|
+
...opts,
|
|
31
|
+
pathname
|
|
32
|
+
}, ...args);
|
|
33
|
+
}
|
|
14
34
|
return {
|
|
15
|
-
Link
|
|
16
|
-
redirect
|
|
35
|
+
Link,
|
|
36
|
+
redirect,
|
|
17
37
|
usePathname: notSupported('usePathname'),
|
|
18
38
|
useRouter: notSupported('useRouter')
|
|
19
39
|
};
|
|
@@ -3,14 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var RequestLocale = require('../../server/RequestLocale.js');
|
|
6
|
-
var
|
|
6
|
+
var baseRedirect = require('../shared/baseRedirect.js');
|
|
7
7
|
|
|
8
|
-
function
|
|
8
|
+
function serverRedirect(params) {
|
|
9
9
|
const locale = RequestLocale.getRequestLocale();
|
|
10
10
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
11
11
|
args[_key - 1] = arguments[_key];
|
|
12
12
|
}
|
|
13
|
-
return
|
|
13
|
+
return baseRedirect.default({
|
|
14
|
+
...params,
|
|
15
|
+
locale
|
|
16
|
+
}, ...args);
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
exports.default =
|
|
19
|
+
exports.default = serverRedirect;
|
|
@@ -3,22 +3,23 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
-
var _rollupPluginBabelHelpers = require('
|
|
6
|
+
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
|
|
7
7
|
var NextLink = require('next/link');
|
|
8
8
|
var navigation = require('next/navigation');
|
|
9
9
|
var React = require('react');
|
|
10
|
-
var useLocale = require('
|
|
11
|
-
var utils = require('
|
|
10
|
+
var useLocale = require('../../react-client/useLocale.js');
|
|
11
|
+
var utils = require('../../shared/utils.js');
|
|
12
12
|
|
|
13
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
14
|
|
|
15
15
|
var NextLink__default = /*#__PURE__*/_interopDefault(NextLink);
|
|
16
16
|
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
17
17
|
|
|
18
|
-
function
|
|
18
|
+
function BaseLink(_ref, ref) {
|
|
19
19
|
let {
|
|
20
20
|
href,
|
|
21
21
|
locale,
|
|
22
|
+
localePrefix,
|
|
22
23
|
prefetch,
|
|
23
24
|
...rest
|
|
24
25
|
} = _ref;
|
|
@@ -27,20 +28,22 @@ function BaseLinkWithLocale(_ref, ref) {
|
|
|
27
28
|
const pathname = navigation.usePathname();
|
|
28
29
|
const defaultLocale = useLocale.default();
|
|
29
30
|
const isChangingLocale = locale !== defaultLocale;
|
|
30
|
-
const [localizedHref, setLocalizedHref] = React.useState(() => utils.isLocalHref(href) &&
|
|
31
|
-
//
|
|
31
|
+
const [localizedHref, setLocalizedHref] = React.useState(() => utils.isLocalHref(href) && (localePrefix !== 'never' || isChangingLocale) ?
|
|
32
|
+
// For the `localePrefix: 'as-needed' strategy, the href shouldn't
|
|
33
|
+
// be prefixed if the locale is the default locale. To determine this, we
|
|
32
34
|
// need a) the default locale and b) the information if we use prefixed
|
|
33
|
-
// routing.
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
// a
|
|
37
|
-
//
|
|
38
|
-
//
|
|
35
|
+
// routing. The default locale can vary by domain, therefore during the
|
|
36
|
+
// RSC as well as the SSR render, we can't determine the default locale
|
|
37
|
+
// statically. Therefore we always prefix the href since this will
|
|
38
|
+
// always result in a valid URL, even if it might cause a redirect. This
|
|
39
|
+
// is better than pointing to a non-localized href during the server
|
|
40
|
+
// render, which would potentially be wrong. The final href is
|
|
41
|
+
// determined in the effect below.
|
|
39
42
|
utils.prefixHref(href, locale) : href);
|
|
40
43
|
React.useEffect(() => {
|
|
41
|
-
if (!pathname) return;
|
|
44
|
+
if (!pathname || localePrefix === 'never') return;
|
|
42
45
|
setLocalizedHref(utils.localizeHref(href, locale, defaultLocale, pathname !== null && pathname !== void 0 ? pathname : undefined));
|
|
43
|
-
}, [defaultLocale, href, locale, pathname]);
|
|
46
|
+
}, [defaultLocale, href, locale, localePrefix, pathname]);
|
|
44
47
|
if (isChangingLocale) {
|
|
45
48
|
if (prefetch && "development" !== 'production') {
|
|
46
49
|
console.error('The `prefetch` prop is currently not supported when using the `locale` prop on `Link` to switch the locale.`');
|
|
@@ -53,6 +56,8 @@ function BaseLinkWithLocale(_ref, ref) {
|
|
|
53
56
|
prefetch: prefetch
|
|
54
57
|
}, rest));
|
|
55
58
|
}
|
|
56
|
-
|
|
59
|
+
const BaseLinkWithRef = /*#__PURE__*/React.forwardRef(BaseLink);
|
|
60
|
+
BaseLinkWithRef.displayName = 'ClientLink';
|
|
61
|
+
var BaseLink$1 = BaseLinkWithRef;
|
|
57
62
|
|
|
58
|
-
exports.default =
|
|
63
|
+
exports.default = BaseLink$1;
|
|
@@ -0,0 +1,16 @@
|
|
|
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 baseRedirect(params) {
|
|
9
|
+
const localizedPathname = params.localePrefix === 'never' ? params.pathname : utils.prefixPathname(params.locale, params.pathname);
|
|
10
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
11
|
+
args[_key - 1] = arguments[_key];
|
|
12
|
+
}
|
|
13
|
+
return navigation.redirect(localizedPathname, ...args);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.default = baseRedirect;
|
|
@@ -15,14 +15,14 @@ function isLocalHref(href) {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
function localizeHref(href, locale) {
|
|
18
|
-
let
|
|
18
|
+
let curLocale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : locale;
|
|
19
19
|
let pathname = arguments.length > 3 ? arguments[3] : undefined;
|
|
20
20
|
if (!isLocalHref(href) || isRelativeHref(href)) {
|
|
21
21
|
return href;
|
|
22
22
|
}
|
|
23
|
-
const isSwitchingLocale = locale !==
|
|
23
|
+
const isSwitchingLocale = locale !== curLocale;
|
|
24
24
|
const isPathnamePrefixed = locale == null || hasPathnamePrefixed(locale, pathname);
|
|
25
|
-
const shouldPrefix =
|
|
25
|
+
const shouldPrefix = isSwitchingLocale || isPathnamePrefixed;
|
|
26
26
|
if (shouldPrefix && locale != null) {
|
|
27
27
|
return prefixHref(href, locale);
|
|
28
28
|
}
|
|
@@ -31,13 +31,13 @@ function localizeHref(href, locale) {
|
|
|
31
31
|
function prefixHref(href, locale) {
|
|
32
32
|
let prefixedHref;
|
|
33
33
|
if (typeof href === 'string') {
|
|
34
|
-
prefixedHref =
|
|
34
|
+
prefixedHref = prefixPathname(locale, href);
|
|
35
35
|
} else {
|
|
36
36
|
prefixedHref = {
|
|
37
37
|
...href
|
|
38
38
|
};
|
|
39
39
|
if (href.pathname) {
|
|
40
|
-
prefixedHref.pathname =
|
|
40
|
+
prefixedHref.pathname = prefixPathname(locale, href.pathname);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
return prefixedHref;
|
|
@@ -45,7 +45,7 @@ function prefixHref(href, locale) {
|
|
|
45
45
|
function unlocalizePathname(pathname, locale) {
|
|
46
46
|
return pathname.replace(new RegExp("^/".concat(locale)), '') || '/';
|
|
47
47
|
}
|
|
48
|
-
function
|
|
48
|
+
function prefixPathname(locale, pathname) {
|
|
49
49
|
let localizedHref = '/' + locale;
|
|
50
50
|
|
|
51
51
|
// Avoid trailing slashes
|
|
@@ -80,8 +80,8 @@ exports.hasPathnamePrefixed = hasPathnamePrefixed;
|
|
|
80
80
|
exports.isLocalHref = isLocalHref;
|
|
81
81
|
exports.isRelativeHref = isRelativeHref;
|
|
82
82
|
exports.localizeHref = localizeHref;
|
|
83
|
-
exports.localizePathname = localizePathname;
|
|
84
83
|
exports.matchesPathname = matchesPathname;
|
|
85
84
|
exports.prefixHref = prefixHref;
|
|
85
|
+
exports.prefixPathname = prefixPathname;
|
|
86
86
|
exports.templateToRegex = templateToRegex;
|
|
87
87
|
exports.unlocalizePathname = unlocalizePathname;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{NextResponse as e}from"next/server";import{COOKIE_LOCALE_NAME as o,HEADER_LOCALE_NAME as l}from"../shared/constants.js";import{matchesPathname as n}from"../shared/utils.js";import t from"./getAlternateLinksHeaderValue.js";import a from"./resolveLocale.js";import{isLocaleSupportedOnDomain as r,getNormalizedPathname as i,getKnownLocaleFromPathname as s,getInternalTemplate as c,formatTemplatePathname as d,getPathWithSearch as f,getBasePath as u,getBestMatchingDomain as m}from"./utils.js";function v(v){const h=function(e){var o,l,n;return{...e,alternateLinks:null===(o=e.alternateLinks)||void 0===o||o,localePrefix:null!==(l=e.localePrefix)&&void 0!==l?l:"always",localeDetection:null===(n=e.localeDetection)||void 0===n||n}}(v);return function(v){var p,x;const{domain:L,locale:P}=a(h,v.headers,v.cookies,v.nextUrl.pathname),
|
|
1
|
+
import{NextResponse as e}from"next/server";import{COOKIE_LOCALE_NAME as o,HEADER_LOCALE_NAME as l}from"../shared/constants.js";import{matchesPathname as n}from"../shared/utils.js";import t from"./getAlternateLinksHeaderValue.js";import a from"./resolveLocale.js";import{isLocaleSupportedOnDomain as r,getNormalizedPathname as i,getKnownLocaleFromPathname as s,getInternalTemplate as c,formatTemplatePathname as d,getPathWithSearch as f,getBasePath as u,getBestMatchingDomain as m}from"./utils.js";function v(v){const h=function(e){var o,l,n;return{...e,alternateLinks:null===(o=e.alternateLinks)||void 0===o||o,localePrefix:null!==(l=e.localePrefix)&&void 0!==l?l:"always",localeDetection:null===(n=e.localeDetection)||void 0===n||n}}(v);return function(v){var p,x;const{domain:L,locale:P}=a(h,v.headers,v.cookies,v.nextUrl.pathname),U=h.localeDetection&&(null===(p=v.cookies.get(o))||void 0===p?void 0:p.value)!==P,g=L?L.defaultLocale===P:P===h.defaultLocale,k=(null===(x=h.domains)||void 0===x?void 0:x.filter((e=>r(P,e))))||[],w=null!=h.domains&&!L;function j(o){return e.rewrite(new URL(o,v.url),function(){const e=new Headers(v.headers);return e.set(l,P),{request:{headers:e}}}())}function y(o,l){const n=new URL(o,v.url);if(k.length>0&&!l){const e=m(L,P,k);e&&(l=e.domain,e.defaultLocale===P&&"as-needed"===h.localePrefix&&(n.pathname=n.pathname.replace("/".concat(P),"")))}var t;l&&(n.protocol=null!==(t=v.headers.get("x-forwarded-proto"))&&void 0!==t?t:v.nextUrl.protocol,n.port="",n.host=l);return e.redirect(n.toString())}const D=i(v.nextUrl.pathname,h.locales),q=s(v.nextUrl.pathname,h.locales),A=null!=q;let H,R,S=v.nextUrl.pathname;if(h.pathnames){let e;if([e=P,R]=c(h.pathnames,D),R){const o=h.pathnames[R],l="string"==typeof o?o:o[P];if(n(l,D))S=d(D,l,R,q);else{const n=h.defaultLocale===P||(null==L?void 0:L.defaultLocale)===P;H=y(f(d(D,"string"==typeof o?o:o[e],l,q||!n?P:void 0),v.nextUrl.search))}}}if(!H)if("/"===S){const e=f("/".concat(P),v.nextUrl.search);H="never"===h.localePrefix||g&&"as-needed"===h.localePrefix?j(e):y(e)}else{const e=f(S,v.nextUrl.search);if(A){const o=u(f(D,v.nextUrl.search),q);if("never"===h.localePrefix)H=y(o);else if(q===P)if(g&&"as-needed"===h.localePrefix)H=y(o);else if(h.domains){const l=m(L,q,k);H=(null==L?void 0:L.domain)===(null==l?void 0:l.domain)||w?j(e):y(o,null==l?void 0:l.domain)}else H=j(e);else H=y("/".concat(P).concat(o))}else H="never"===h.localePrefix||g&&("as-needed"===h.localePrefix||h.domains)?j("/".concat(P).concat(e)):y("/".concat(P).concat(e))}var z;(U&&H.cookies.set(o,P,{sameSite:"strict",maxAge:31536e3}),"never"!==h.localePrefix&&h.alternateLinks&&h.locales.length>1)&&H.headers.set("Link",t({config:h,localizedPathnames:null!=R?null===(z=h.pathnames)||void 0===z?void 0:z[R]:void 0,request:v,resolvedLocale:P}));return H}}export{v as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as t}from"react";import a from"../../react-client/useLocale.js";import l from"../shared/BaseLink.js";function o(t,o){let{locale:n,...s}=t;const i=a(),c=n||i;return r.createElement(l,e({ref:o,hrefLang:c,locale:c},s))}const n=t(o);n.displayName="ClientLink";var s=n;export{s as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"../../react-client/useLocale.js";import r from"../shared/baseRedirect.js";function t(t){let a;try{a=e()}catch(e){throw new Error("`redirect()` can only be called during render. To redirect in an event handler or similar, you can use `useRouter()` instead.")}for(var n=arguments.length,o=new Array(n>1?n-1:0),c=1;c<n;c++)o[c-1]=arguments[c];return r({...t,locale:a},...o)}export{t as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as t}from"react";import
|
|
1
|
+
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as t}from"react";import a from"../../react-client/useLocale.js";import{getRoute as o,compileLocalizedPathname as n,normalizeNameOrNameWithParams as l}from"../shared/utils.js";import c from"./ClientLink.js";import s from"./clientRedirect.js";import i from"./useBasePathname.js";import u from"./useBaseRouter.js";function f(f){function m(){const e=a();if(!f.locales.includes(e))throw new Error('Unknown locale encountered: "'.concat(e,'". Make sure to validate the locale in `app/[locale]/layout.tsx`.'));return e}function p(t,a){let{href:o,locale:l,...s}=t;const i=m(),u=l||i;return r.createElement(c,e({ref:a,href:n({locale:u,pathname:o,params:"object"==typeof o?o.params:void 0,pathnames:f.pathnames}),locale:l,localePrefix:f.localePrefix},s))}const h=t(p);function d(e){let{href:r,locale:t}=e;return n({...l(r),locale:t,pathnames:f.pathnames})}return h.displayName="Link",{Link:h,redirect:function(e){const r=d({href:e,locale:m()});for(var t=arguments.length,a=new Array(t>1?t-1:0),o=1;o<t;o++)a[o-1]=arguments[o];return s({...f,pathname:r},...a)},usePathname:function(){const e=i(),r=m();return o({pathname:e,locale:r,pathnames:f.pathnames})},useRouter:function(){const e=u(),r=m();return{...e,push(t){for(var a,o=arguments.length,n=new Array(o>1?o-1:0),l=1;l<o;l++)n[l-1]=arguments[l];const c=d({href:t,locale:(null===(a=n[0])||void 0===a?void 0:a.locale)||r});return e.push(c,...n)},replace(t){for(var a,o=arguments.length,n=new Array(o>1?o-1:0),l=1;l<o;l++)n[l-1]=arguments[l];const c=d({href:t,locale:(null===(a=n[0])||void 0===a?void 0:a.locale)||r});return e.replace(c,...n)},prefetch(t){for(var a,o=arguments.length,n=new Array(o>1?o-1:0),l=1;l<o;l++)n[l-1]=arguments[l];const c=d({href:t,locale:(null===(a=n[0])||void 0===a?void 0:a.locale)||r});return e.prefetch(c,...n)}}},getPathname:d}}export{f as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"./
|
|
1
|
+
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as t}from"react";import n from"./ClientLink.js";import o from"./clientRedirect.js";import a from"./useBasePathname.js";import i from"./useBaseRouter.js";function m(m){function s(t,o){return r.createElement(n,e({ref:o,localePrefix:m.localePrefix},t))}const l=t(s);return l.displayName="Link",{Link:l,redirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return o({...m,pathname:e},...t)},usePathname:a,useRouter:i}}export{m as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"react";import t from"../shared/BaseLink.js";import a from"../../server/getLocale.js";async function l(l){let{locale:o,...s}=l;return r.createElement(t,e({locale:o||await a()},s))}export{l as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import
|
|
1
|
+
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"react";import{getRequestLocale as t}from"../../server/RequestLocale.js";import{compileLocalizedPathname as o,normalizeNameOrNameWithParams as n}from"../shared/utils.js";import a from"./ServerLink.js";import l from"./serverRedirect.js";function s(s){let{localePrefix:c,locales:i,pathnames:m}=s;function u(e){let{href:r,locale:t}=e;return o({...n(r),locale:t,pathnames:m})}function f(e){return()=>{throw new Error("`".concat(e,"` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."))}}return{Link:function(n){let{href:l,locale:s,...i}=n;const u=t(),f=s||u;return r.createElement(a,e({href:o({locale:f,pathname:l,params:"object"==typeof l?l.params:void 0,pathnames:m}),locale:s,localePrefix:c},i))},redirect:function(e){const r=u({href:e,locale:t()});for(var o=arguments.length,n=new Array(o>1?o-1:0),a=1;a<o;a++)n[a-1]=arguments[a];return l({localePrefix:c,pathname:r},...n)},getPathname:u,usePathname:f("usePathname"),useRouter:f("useRouter")}}export{s as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"./
|
|
1
|
+
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"react";import t from"./ServerLink.js";import o from"./serverRedirect.js";function n(n){function u(e){return()=>{throw new Error("`".concat(e,"` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."))}}return{Link:function(o){return r.createElement(t,e({localePrefix:n.localePrefix},o))},redirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),u=1;u<r;u++)t[u-1]=arguments[u];return o({...n,pathname:e},...t)},usePathname:u("usePathname"),useRouter:u("useRouter")}}export{n as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getRequestLocale as e}from"../../server/RequestLocale.js";import r from"../shared/baseRedirect.js";function o(o){const t=e();for(var a=arguments.length,s=new Array(a>1?a-1:0),n=1;n<a;n++)s[n-1]=arguments[n];return r({...o,locale:t},...s)}export{o as default};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"next/link";import{usePathname as t}from"next/navigation";import o,{forwardRef as l,useState as n,useEffect as i}from"react";import a from"../../react-client/useLocale.js";import{isLocalHref as p,prefixHref as c,localizeHref as s}from"../../shared/utils.js";function f(l,f){let{href:m,locale:u,localePrefix:h,prefetch:d,...v}=l;const x=t(),g=a(),j=u!==g,[k,L]=n((()=>p(m)&&("never"!==h||j)?c(m,u):m));return i((()=>{x&&"never"!==h&&L(s(m,u,g,null!=x?x:void 0))}),[g,m,u,h,x]),j&&(d&&console.error("The `prefetch` prop is currently not supported when using the `locale` prop on `Link` to switch the locale.`"),d=!1),o.createElement(r,e({ref:f,href:k,prefetch:d},v))}const m=l(f);m.displayName="ClientLink";var u=m;export{u as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{redirect as e}from"next/navigation";import{prefixPathname as r}from"../../shared/utils.js";function a(a){const t="never"===a.localePrefix?a.pathname:r(a.locale,a.pathname);for(var n=arguments.length,o=new Array(n>1?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];return e(t,...o)}export{a as default};
|
package/dist/esm/shared/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(t){const n="object"==typeof t?t.pathname:t;return null!=n&&!n.startsWith("/")}function n(t){if("object"==typeof t)return null==t.host&&null==t.hostname;return!/^[a-z]+:/i.test(t)}function e(e,c){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:c,a=arguments.length>3?arguments[3]:void 0;if(!n(e)||t(e))return e;const l=c!==o
|
|
1
|
+
function t(t){const n="object"==typeof t?t.pathname:t;return null!=n&&!n.startsWith("/")}function n(t){if("object"==typeof t)return null==t.host&&null==t.hostname;return!/^[a-z]+:/i.test(t)}function e(e,c){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:c,a=arguments.length>3?arguments[3]:void 0;if(!n(e)||t(e))return e;const l=c!==o,i=null==c||u(c,a);return(l||i)&&null!=c?r(e,c):e}function r(t,n){let e;return"string"==typeof t?e=o(n,t):(e={...t},t.pathname&&(e.pathname=o(n,t.pathname))),e}function c(t,n){return t.replace(new RegExp("^/".concat(n)),"")||"/"}function o(t,n){let e="/"+t;return/^\/(\?.*)?$/.test(n)&&(n=n.slice(1)),e+=n,e}function u(t,n){const e="/".concat(t);return n===e||n.startsWith("".concat(e,"/"))}function a(t,n){return l(t).test(n)}function l(t){const n=t.replace(/\[([^\]]+)\]/g,(t=>t.startsWith("[...")||t.startsWith("[[...")?"(.*)":"([^/]+)")).replaceAll("(.*)]","(.*)");return new RegExp("^".concat(n,"$"))}export{u as hasPathnamePrefixed,n as isLocalHref,t as isRelativeHref,e as localizeHref,a as matchesPathname,r as prefixHref,o as prefixPathname,l as templateToRegex,c as unlocalizePathname};
|