next-intl 3.6.0 → 3.8.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 (29) hide show
  1. package/dist/development/navigation/react-client/clientPermanentRedirect.js +25 -0
  2. package/dist/development/navigation/react-client/createLocalizedPathnamesNavigation.js +23 -6
  3. package/dist/development/navigation/react-client/createSharedPathnamesNavigation.js +11 -0
  4. package/dist/development/navigation/react-server/createLocalizedPathnamesNavigation.js +16 -0
  5. package/dist/development/navigation/react-server/createSharedPathnamesNavigation.js +11 -0
  6. package/dist/development/navigation/react-server/serverPermanentRedirect.js +19 -0
  7. package/dist/development/navigation/shared/basePermanentRedirect.js +16 -0
  8. package/dist/esm/navigation/react-client/clientPermanentRedirect.js +1 -0
  9. package/dist/esm/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
  10. package/dist/esm/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
  11. package/dist/esm/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -1
  12. package/dist/esm/navigation/react-server/createSharedPathnamesNavigation.js +1 -1
  13. package/dist/esm/navigation/react-server/serverPermanentRedirect.js +1 -0
  14. package/dist/esm/navigation/shared/basePermanentRedirect.js +1 -0
  15. package/dist/production/navigation/react-client/clientPermanentRedirect.js +1 -0
  16. package/dist/production/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
  17. package/dist/production/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
  18. package/dist/production/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -1
  19. package/dist/production/navigation/react-server/createSharedPathnamesNavigation.js +1 -1
  20. package/dist/production/navigation/react-server/serverPermanentRedirect.js +1 -0
  21. package/dist/production/navigation/shared/basePermanentRedirect.js +1 -0
  22. package/dist/types/src/navigation/react-client/clientPermanentRedirect.d.ts +6 -0
  23. package/dist/types/src/navigation/react-client/createLocalizedPathnamesNavigation.d.ts +4 -3
  24. package/dist/types/src/navigation/react-client/createSharedPathnamesNavigation.d.ts +1 -0
  25. package/dist/types/src/navigation/react-server/createLocalizedPathnamesNavigation.d.ts +1 -0
  26. package/dist/types/src/navigation/react-server/createSharedPathnamesNavigation.d.ts +1 -0
  27. package/dist/types/src/navigation/react-server/serverPermanentRedirect.d.ts +6 -0
  28. package/dist/types/src/navigation/shared/basePermanentRedirect.d.ts +7 -0
  29. package/package.json +8 -8
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var useLocale = require('../../react-client/useLocale.js');
6
+ var basePermanentRedirect = require('../shared/basePermanentRedirect.js');
7
+
8
+ function clientPermanentRedirect(params) {
9
+ let locale;
10
+ try {
11
+ // eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context here is fine, since `redirect` should be called during render
12
+ locale = useLocale.default();
13
+ } catch (e) {
14
+ throw new Error('`permanentRedirect()` can only be called during render. To redirect in an event handler or similar, you can use `useRouter()` instead.' );
15
+ }
16
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
17
+ args[_key - 1] = arguments[_key];
18
+ }
19
+ return basePermanentRedirect.default({
20
+ ...params,
21
+ locale
22
+ }, ...args);
23
+ }
24
+
25
+ exports.default = clientPermanentRedirect;
@@ -7,6 +7,7 @@ var React = require('react');
7
7
  var useLocale = require('../../react-client/useLocale.js');
8
8
  var utils = require('../shared/utils.js');
9
9
  var ClientLink = require('./ClientLink.js');
10
+ var clientPermanentRedirect = require('./clientPermanentRedirect.js');
10
11
  var clientRedirect = require('./clientRedirect.js');
11
12
  var useBasePathname = require('./useBasePathname.js');
12
13
  var useBaseRouter = require('./useBaseRouter.js');
@@ -63,6 +64,21 @@ function createLocalizedPathnamesNavigation(opts) {
63
64
  pathname: resolvedHref
64
65
  }, ...args);
65
66
  }
67
+ function permanentRedirect(href) {
68
+ // eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context here is fine, since `redirect` should be called during render
69
+ const locale = useTypedLocale();
70
+ const resolvedHref = getPathname({
71
+ href,
72
+ locale
73
+ });
74
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
75
+ args[_key2 - 1] = arguments[_key2];
76
+ }
77
+ return clientPermanentRedirect.default({
78
+ ...opts,
79
+ pathname: resolvedHref
80
+ }, ...args);
81
+ }
66
82
  function useRouter() {
67
83
  const baseRouter = useBaseRouter.default();
68
84
  const defaultLocale = useTypedLocale();
@@ -70,8 +86,8 @@ function createLocalizedPathnamesNavigation(opts) {
70
86
  ...baseRouter,
71
87
  push(href) {
72
88
  var _args$;
73
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
74
- args[_key2 - 1] = arguments[_key2];
89
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
90
+ args[_key3 - 1] = arguments[_key3];
75
91
  }
76
92
  const resolvedHref = getPathname({
77
93
  href,
@@ -81,8 +97,8 @@ function createLocalizedPathnamesNavigation(opts) {
81
97
  },
82
98
  replace(href) {
83
99
  var _args$2;
84
- for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
85
- args[_key3 - 1] = arguments[_key3];
100
+ for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
101
+ args[_key4 - 1] = arguments[_key4];
86
102
  }
87
103
  const resolvedHref = getPathname({
88
104
  href,
@@ -92,8 +108,8 @@ function createLocalizedPathnamesNavigation(opts) {
92
108
  },
93
109
  prefetch(href) {
94
110
  var _args$3;
95
- for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
96
- args[_key4 - 1] = arguments[_key4];
111
+ for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
112
+ args[_key5 - 1] = arguments[_key5];
97
113
  }
98
114
  const resolvedHref = getPathname({
99
115
  href,
@@ -127,6 +143,7 @@ function createLocalizedPathnamesNavigation(opts) {
127
143
  return {
128
144
  Link: LinkWithRef,
129
145
  redirect,
146
+ permanentRedirect,
130
147
  usePathname,
131
148
  useRouter,
132
149
  getPathname
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
6
  var React = require('react');
7
7
  var ClientLink = require('./ClientLink.js');
8
+ var clientPermanentRedirect = require('./clientPermanentRedirect.js');
8
9
  var clientRedirect = require('./clientRedirect.js');
9
10
  var useBasePathname = require('./useBasePathname.js');
10
11
  var useBaseRouter = require('./useBaseRouter.js');
@@ -31,6 +32,15 @@ function createSharedPathnamesNavigation(opts) {
31
32
  pathname
32
33
  }, ...args);
33
34
  }
35
+ function permanentRedirect(pathname) {
36
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
37
+ args[_key2 - 1] = arguments[_key2];
38
+ }
39
+ return clientPermanentRedirect.default({
40
+ ...opts,
41
+ pathname
42
+ }, ...args);
43
+ }
34
44
  function usePathname() {
35
45
  // @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.
36
46
  return useBasePathname.default();
@@ -38,6 +48,7 @@ function createSharedPathnamesNavigation(opts) {
38
48
  return {
39
49
  Link: LinkWithRef,
40
50
  redirect,
51
+ permanentRedirect,
41
52
  usePathname,
42
53
  useRouter: useBaseRouter.default
43
54
  };
@@ -7,6 +7,7 @@ var React = require('react');
7
7
  var RequestLocale = require('../../server/react-server/RequestLocale.js');
8
8
  var utils = require('../shared/utils.js');
9
9
  var ServerLink = require('./ServerLink.js');
10
+ var serverPermanentRedirect = require('./serverPermanentRedirect.js');
10
11
  var serverRedirect = require('./serverRedirect.js');
11
12
 
12
13
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -54,6 +55,20 @@ function createLocalizedPathnamesNavigation(_ref) {
54
55
  pathname
55
56
  }, ...args);
56
57
  }
58
+ function permanentRedirect(href) {
59
+ const locale = RequestLocale.getRequestLocale();
60
+ const pathname = getPathname({
61
+ href,
62
+ locale
63
+ });
64
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
65
+ args[_key2 - 1] = arguments[_key2];
66
+ }
67
+ return serverPermanentRedirect.default({
68
+ localePrefix,
69
+ pathname
70
+ }, ...args);
71
+ }
57
72
  function getPathname(_ref3) {
58
73
  let {
59
74
  href,
@@ -73,6 +88,7 @@ function createLocalizedPathnamesNavigation(_ref) {
73
88
  return {
74
89
  Link,
75
90
  redirect,
91
+ permanentRedirect,
76
92
  getPathname,
77
93
  usePathname: notSupported('usePathname'),
78
94
  useRouter: notSupported('useRouter')
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
6
6
  var React = require('react');
7
7
  var ServerLink = require('./ServerLink.js');
8
+ var serverPermanentRedirect = require('./serverPermanentRedirect.js');
8
9
  var serverRedirect = require('./serverRedirect.js');
9
10
 
10
11
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -31,9 +32,19 @@ function createSharedPathnamesNavigation(opts) {
31
32
  pathname
32
33
  }, ...args);
33
34
  }
35
+ function permanentRedirect(pathname) {
36
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
37
+ args[_key2 - 1] = arguments[_key2];
38
+ }
39
+ return serverPermanentRedirect.default({
40
+ ...opts,
41
+ pathname
42
+ }, ...args);
43
+ }
34
44
  return {
35
45
  Link,
36
46
  redirect,
47
+ permanentRedirect,
37
48
  usePathname: notSupported('usePathname'),
38
49
  useRouter: notSupported('useRouter')
39
50
  };
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var RequestLocale = require('../../server/react-server/RequestLocale.js');
6
+ var basePermanentRedirect = require('../shared/basePermanentRedirect.js');
7
+
8
+ function serverPermanentRedirect(params) {
9
+ const locale = RequestLocale.getRequestLocale();
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 basePermanentRedirect.default({
14
+ ...params,
15
+ locale
16
+ }, ...args);
17
+ }
18
+
19
+ exports.default = serverPermanentRedirect;
@@ -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 basePermanentRedirect(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.permanentRedirect(localizedPathname, ...args);
14
+ }
15
+
16
+ exports.default = basePermanentRedirect;
@@ -0,0 +1 @@
1
+ import e from"../../react-client/useLocale.js";import r from"../shared/basePermanentRedirect.js";function n(n){let t;try{t=e()}catch(e){throw new Error("`permanentRedirect()` can only be called during render. To redirect in an event handler or similar, you can use `useRouter()` instead.")}for(var a=arguments.length,o=new Array(a>1?a-1:0),c=1;c<a;c++)o[c-1]=arguments[c];return r({...n,locale:t},...o)}export{n as default};
@@ -1 +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{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 e?o({pathname:e,locale:r,pathnames:f.pathnames}):e},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
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as t}from"react";import n from"../../react-client/useLocale.js";import{getRoute as a,compileLocalizedPathname as o,normalizeNameOrNameWithParams as l}from"../shared/utils.js";import c from"./ClientLink.js";import s from"./clientPermanentRedirect.js";import i from"./clientRedirect.js";import u from"./useBasePathname.js";import f from"./useBaseRouter.js";function m(m){function p(){const e=n();if(!m.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 h(t,n){let{href:a,locale:l,...s}=t;const i=p(),u=l||i;return r.createElement(c,e({ref:n,href:o({locale:u,pathname:a,params:"object"==typeof a?a.params:void 0,pathnames:m.pathnames}),locale:l,localePrefix:m.localePrefix},s))}const d=t(h);function v(e){let{href:r,locale:t}=e;return o({...l(r),locale:t,pathnames:m.pathnames})}return d.displayName="Link",{Link:d,redirect:function(e){const r=v({href:e,locale:p()});for(var t=arguments.length,n=new Array(t>1?t-1:0),a=1;a<t;a++)n[a-1]=arguments[a];return i({...m,pathname:r},...n)},permanentRedirect:function(e){const r=v({href:e,locale:p()});for(var t=arguments.length,n=new Array(t>1?t-1:0),a=1;a<t;a++)n[a-1]=arguments[a];return s({...m,pathname:r},...n)},usePathname:function(){const e=u(),r=p();return e?a({pathname:e,locale:r,pathnames:m.pathnames}):e},useRouter:function(){const e=f(),r=p();return{...e,push(t){for(var n,a=arguments.length,o=new Array(a>1?a-1:0),l=1;l<a;l++)o[l-1]=arguments[l];const c=v({href:t,locale:(null===(n=o[0])||void 0===n?void 0:n.locale)||r});return e.push(c,...o)},replace(t){for(var n,a=arguments.length,o=new Array(a>1?a-1:0),l=1;l<a;l++)o[l-1]=arguments[l];const c=v({href:t,locale:(null===(n=o[0])||void 0===n?void 0:n.locale)||r});return e.replace(c,...o)},prefetch(t){for(var n,a=arguments.length,o=new Array(a>1?a-1:0),l=1;l<a;l++)o[l-1]=arguments[l];const c=v({href:t,locale:(null===(n=o[0])||void 0===n?void 0:n.locale)||r});return e.prefetch(c,...o)}}},getPathname:v}}export{m as default};
@@ -1 +1 @@
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 i from"./useBasePathname.js";import a from"./useBaseRouter.js";function u(u){function l(t,o){return r.createElement(n,e({ref:o,localePrefix:null==u?void 0:u.localePrefix},t))}const m=t(l);return m.displayName="Link",{Link:m,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({...u,pathname:e},...t)},usePathname:function(){return i()},useRouter:a}}export{u as default};
1
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as t}from"react";import n from"./ClientLink.js";import o from"./clientPermanentRedirect.js";import i from"./clientRedirect.js";import a from"./useBasePathname.js";import m from"./useBaseRouter.js";function u(u){function l(t,o){return r.createElement(n,e({ref:o,localePrefix:null==u?void 0:u.localePrefix},t))}const f=t(l);return f.displayName="Link",{Link:f,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 i({...u,pathname:e},...t)},permanentRedirect: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({...u,pathname:e},...t)},usePathname:function(){return a()},useRouter:m}}export{u as default};
@@ -1 +1 @@
1
- import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"react";import{getRequestLocale as t}from"../../server/react-server/RequestLocale.js";import{compileLocalizedPathname as o,normalizeNameOrNameWithParams as a}from"../shared/utils.js";import n 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({...a(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(a){let{href:l,locale:s,...i}=a;const u=t(),f=s||u;return r.createElement(n,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,a=new Array(o>1?o-1:0),n=1;n<o;n++)a[n-1]=arguments[n];return l({localePrefix:c,pathname:r},...a)},getPathname:u,usePathname:f("usePathname"),useRouter:f("useRouter")}}export{s as default};
1
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"react";import{getRequestLocale as t}from"../../server/react-server/RequestLocale.js";import{compileLocalizedPathname as o,normalizeNameOrNameWithParams as n}from"../shared/utils.js";import a from"./ServerLink.js";import l from"./serverPermanentRedirect.js";import c from"./serverRedirect.js";function s(s){let{localePrefix:i,locales:m,pathnames:u}=s;function f(e){let{href:r,locale:t}=e;return o({...n(r),locale:t,pathnames:u})}function p(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:c,...s}=n;const m=t(),f=c||m;return r.createElement(a,e({href:o({locale:f,pathname:l,params:"object"==typeof l?l.params:void 0,pathnames:u}),locale:c,localePrefix:i},s))},redirect:function(e){const r=f({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 c({localePrefix:i,pathname:r},...n)},permanentRedirect:function(e){const r=f({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:i,pathname:r},...n)},getPathname:f,usePathname:p("usePathname"),useRouter:p("useRouter")}}export{s as default};
@@ -1 +1 @@
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:null==n?void 0: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};
1
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"react";import t from"./ServerLink.js";import n from"./serverPermanentRedirect.js";import o from"./serverRedirect.js";function a(a){function i(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){return r.createElement(t,e({localePrefix:null==a?void 0:a.localePrefix},n))},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({...a,pathname:e},...t)},permanentRedirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),o=1;o<r;o++)t[o-1]=arguments[o];return n({...a,pathname:e},...t)},usePathname:i("usePathname"),useRouter:i("useRouter")}}export{a as default};
@@ -0,0 +1 @@
1
+ import{getRequestLocale as e}from"../../server/react-server/RequestLocale.js";import r from"../shared/basePermanentRedirect.js";function t(t){const a=e();for(var o=arguments.length,s=new Array(o>1?o-1:0),n=1;n<o;n++)s[n-1]=arguments[n];return r({...t,locale:a},...s)}export{t as default};
@@ -0,0 +1 @@
1
+ import{permanentRedirect 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};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../react-client/useLocale.js"),r=require("../shared/basePermanentRedirect.js");exports.default=function(t){let a;try{a=e.default()}catch(e){throw new Error(void 0)}for(var l=arguments.length,o=new Array(l>1?l-1:0),u=1;u<l;u++)o[u-1]=arguments[u];return r.default({...t,locale:a},...o)};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),a=require("../../react-client/useLocale.js"),t=require("../shared/utils.js"),l=require("./ClientLink.js"),n=require("./clientRedirect.js"),o=require("./useBasePathname.js"),u=require("./useBaseRouter.js");function c(e){return e&&e.__esModule?e:{default:e}}var i=c(r);exports.default=function(c){function s(){const e=a.default();if(!c.locales.includes(e))throw new Error(void 0);return e}function f(r,a){let{href:n,locale:o,...u}=r;const f=s(),h=o||f;return i.default.createElement(l.default,e.extends({ref:a,href:t.compileLocalizedPathname({locale:h,pathname:n,params:"object"==typeof n?n.params:void 0,pathnames:c.pathnames}),locale:o,localePrefix:c.localePrefix},u))}const h=r.forwardRef(f);function d(e){let{href:r,locale:a}=e;return t.compileLocalizedPathname({...t.normalizeNameOrNameWithParams(r),locale:a,pathnames:c.pathnames})}return h.displayName="Link",{Link:h,redirect:function(e){const r=d({href:e,locale:s()});for(var a=arguments.length,t=new Array(a>1?a-1:0),l=1;l<a;l++)t[l-1]=arguments[l];return n.default({...c,pathname:r},...t)},usePathname:function(){const e=o.default(),r=s();return e?t.getRoute({pathname:e,locale:r,pathnames:c.pathnames}):e},useRouter:function(){const e=u.default(),r=s();return{...e,push(a){for(var t,l=arguments.length,n=new Array(l>1?l-1:0),o=1;o<l;o++)n[o-1]=arguments[o];const u=d({href:a,locale:(null===(t=n[0])||void 0===t?void 0:t.locale)||r});return e.push(u,...n)},replace(a){for(var t,l=arguments.length,n=new Array(l>1?l-1:0),o=1;o<l;o++)n[o-1]=arguments[o];const u=d({href:a,locale:(null===(t=n[0])||void 0===t?void 0:t.locale)||r});return e.replace(u,...n)},prefetch(a){for(var t,l=arguments.length,n=new Array(l>1?l-1:0),o=1;o<l;o++)n[o-1]=arguments[o];const u=d({href:a,locale:(null===(t=n[0])||void 0===t?void 0:t.locale)||r});return e.prefetch(u,...n)}}},getPathname:d}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),a=require("../../react-client/useLocale.js"),t=require("../shared/utils.js"),n=require("./ClientLink.js"),l=require("./clientPermanentRedirect.js"),o=require("./clientRedirect.js"),u=require("./useBasePathname.js"),c=require("./useBaseRouter.js");function i(e){return e&&e.__esModule?e:{default:e}}var s=i(r);exports.default=function(i){function f(){const e=a.default();if(!i.locales.includes(e))throw new Error(void 0);return e}function h(r,a){let{href:l,locale:o,...u}=r;const c=f(),h=o||c;return s.default.createElement(n.default,e.extends({ref:a,href:t.compileLocalizedPathname({locale:h,pathname:l,params:"object"==typeof l?l.params:void 0,pathnames:i.pathnames}),locale:o,localePrefix:i.localePrefix},u))}const d=r.forwardRef(h);function p(e){let{href:r,locale:a}=e;return t.compileLocalizedPathname({...t.normalizeNameOrNameWithParams(r),locale:a,pathnames:i.pathnames})}return d.displayName="Link",{Link:d,redirect:function(e){const r=p({href:e,locale:f()});for(var a=arguments.length,t=new Array(a>1?a-1:0),n=1;n<a;n++)t[n-1]=arguments[n];return o.default({...i,pathname:r},...t)},permanentRedirect:function(e){const r=p({href:e,locale:f()});for(var a=arguments.length,t=new Array(a>1?a-1:0),n=1;n<a;n++)t[n-1]=arguments[n];return l.default({...i,pathname:r},...t)},usePathname:function(){const e=u.default(),r=f();return e?t.getRoute({pathname:e,locale:r,pathnames:i.pathnames}):e},useRouter:function(){const e=c.default(),r=f();return{...e,push(a){for(var t,n=arguments.length,l=new Array(n>1?n-1:0),o=1;o<n;o++)l[o-1]=arguments[o];const u=p({href:a,locale:(null===(t=l[0])||void 0===t?void 0:t.locale)||r});return e.push(u,...l)},replace(a){for(var t,n=arguments.length,l=new Array(n>1?n-1:0),o=1;o<n;o++)l[o-1]=arguments[o];const u=p({href:a,locale:(null===(t=l[0])||void 0===t?void 0:t.locale)||r});return e.replace(u,...l)},prefetch(a){for(var t,n=arguments.length,l=new Array(n>1?n-1:0),o=1;o<n;o++)l[o-1]=arguments[o];const u=p({href:a,locale:(null===(t=l[0])||void 0===t?void 0:t.locale)||r});return e.prefetch(u,...l)}}},getPathname:p}};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("./ClientLink.js"),u=require("./clientRedirect.js"),n=require("./useBasePathname.js"),a=require("./useBaseRouter.js");function l(e){return e&&e.__esModule?e:{default:e}}var i=l(r);exports.default=function(l){function s(r,u){return i.default.createElement(t.default,e.extends({ref:u,localePrefix:null==l?void 0:l.localePrefix},r))}const f=r.forwardRef(s);return f.displayName="Link",{Link:f,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 u.default({...l,pathname:e},...t)},usePathname:function(){return n.default()},useRouter:a.default}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("./ClientLink.js"),n=require("./clientPermanentRedirect.js"),u=require("./clientRedirect.js"),a=require("./useBasePathname.js"),i=require("./useBaseRouter.js");function l(e){return e&&e.__esModule?e:{default:e}}var f=l(r);exports.default=function(l){function s(r,n){return f.default.createElement(t.default,e.extends({ref:n,localePrefix:null==l?void 0:l.localePrefix},r))}const o=r.forwardRef(s);return o.displayName="Link",{Link:o,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 u.default({...l,pathname:e},...t)},permanentRedirect: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 n.default({...l,pathname:e},...t)},usePathname:function(){return a.default()},useRouter:i.default}};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("../../server/react-server/RequestLocale.js"),a=require("../shared/utils.js"),o=require("./ServerLink.js"),n=require("./serverRedirect.js");function l(e){return e&&e.__esModule?e:{default:e}}var u=l(r);exports.default=function(r){let{localePrefix:l,locales:s,pathnames:c}=r;function i(e){let{href:r,locale:t}=e;return a.compileLocalizedPathname({...a.normalizeNameOrNameWithParams(r),locale:t,pathnames:c})}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(r){let{href:n,locale:s,...i}=r;const f=t.getRequestLocale(),m=s||f;return u.default.createElement(o.default,e.extends({href:a.compileLocalizedPathname({locale:m,pathname:n,params:"object"==typeof n?n.params:void 0,pathnames:c}),locale:s,localePrefix:l},i))},redirect:function(e){const r=i({href:e,locale:t.getRequestLocale()});for(var a=arguments.length,o=new Array(a>1?a-1:0),u=1;u<a;u++)o[u-1]=arguments[u];return n.default({localePrefix:l,pathname:r},...o)},getPathname:i,usePathname:f("usePathname"),useRouter:f("useRouter")}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("../../server/react-server/RequestLocale.js"),a=require("../shared/utils.js"),n=require("./ServerLink.js"),o=require("./serverPermanentRedirect.js"),l=require("./serverRedirect.js");function u(e){return e&&e.__esModule?e:{default:e}}var c=u(r);exports.default=function(r){let{localePrefix:u,locales:s,pathnames:i}=r;function f(e){let{href:r,locale:t}=e;return a.compileLocalizedPathname({...a.normalizeNameOrNameWithParams(r),locale:t,pathnames:i})}function m(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(r){let{href:o,locale:l,...s}=r;const f=t.getRequestLocale(),m=l||f;return c.default.createElement(n.default,e.extends({href:a.compileLocalizedPathname({locale:m,pathname:o,params:"object"==typeof o?o.params:void 0,pathnames:i}),locale:l,localePrefix:u},s))},redirect:function(e){const r=f({href:e,locale:t.getRequestLocale()});for(var a=arguments.length,n=new Array(a>1?a-1:0),o=1;o<a;o++)n[o-1]=arguments[o];return l.default({localePrefix:u,pathname:r},...n)},permanentRedirect:function(e){const r=f({href:e,locale:t.getRequestLocale()});for(var a=arguments.length,n=new Array(a>1?a-1:0),l=1;l<a;l++)n[l-1]=arguments[l];return o.default({localePrefix:u,pathname:r},...n)},getPathname:f,usePathname:m("usePathname"),useRouter:m("useRouter")}};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("./ServerLink.js"),n=require("./serverRedirect.js");function u(e){return e&&e.__esModule?e:{default:e}}var o=u(r);exports.default=function(r){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(n){return o.default.createElement(t.default,e.extends({localePrefix:null==r?void 0:r.localePrefix},n))},redirect:function(e){for(var t=arguments.length,u=new Array(t>1?t-1:0),o=1;o<t;o++)u[o-1]=arguments[o];return n.default({...r,pathname:e},...u)},usePathname:u("usePathname"),useRouter:u("useRouter")}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("./ServerLink.js"),n=require("./serverPermanentRedirect.js"),u=require("./serverRedirect.js");function o(e){return e&&e.__esModule?e:{default:e}}var a=o(r);exports.default=function(r){function o(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){return a.default.createElement(t.default,e.extends({localePrefix:null==r?void 0:r.localePrefix},n))},redirect:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];return u.default({...r,pathname:e},...n)},permanentRedirect:function(e){for(var t=arguments.length,u=new Array(t>1?t-1:0),o=1;o<t;o++)u[o-1]=arguments[o];return n.default({...r,pathname:e},...u)},usePathname:o("usePathname"),useRouter:o("useRouter")}};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../server/react-server/RequestLocale.js"),r=require("../shared/basePermanentRedirect.js");exports.default=function(t){const s=e.getRequestLocale();for(var a=arguments.length,u=new Array(a>1?a-1:0),o=1;o<a;o++)u[o-1]=arguments[o];return r.default({...t,locale:s},...u)};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/navigation"),r=require("../../shared/utils.js");exports.default=function(t){const a="never"===t.localePrefix?t.pathname:r.prefixPathname(t.locale,t.pathname);for(var n=arguments.length,i=new Array(n>1?n-1:0),o=1;o<n;o++)i[o-1]=arguments[o];return e.permanentRedirect(a,...i)};
@@ -0,0 +1,6 @@
1
+ import { LocalePrefix, ParametersExceptFirst } from '../../shared/types';
2
+ import basePermanentRedirect from '../shared/basePermanentRedirect';
3
+ export default function clientPermanentRedirect(params: {
4
+ localePrefix?: LocalePrefix;
5
+ pathname: string;
6
+ }, ...args: ParametersExceptFirst<typeof basePermanentRedirect>): never;
@@ -58,15 +58,16 @@ export default function createLocalizedPathnamesNavigation<Locales extends AllLo
58
58
  ref?: ComponentProps<typeof ClientLink>['ref'];
59
59
  }) => ReactElement;
60
60
  redirect: <Pathname_1 extends keyof PathnamesConfig>(href: HrefOrHrefWithParams<Pathname_1>, type?: import("next/navigation").RedirectType | undefined) => never;
61
+ permanentRedirect: <Pathname_2 extends keyof PathnamesConfig>(href: HrefOrHrefWithParams<Pathname_2>, type?: import("next/navigation").RedirectType | undefined) => never;
61
62
  usePathname: () => keyof PathnamesConfig;
62
63
  useRouter: () => {
63
- push<Pathname_2 extends keyof PathnamesConfig>(href: HrefOrHrefWithParams<Pathname_2>, options?: (import("next/dist/shared/lib/app-router-context.shared-runtime").NavigateOptions & {
64
+ push<Pathname_3 extends keyof PathnamesConfig>(href: HrefOrHrefWithParams<Pathname_3>, options?: (import("next/dist/shared/lib/app-router-context.shared-runtime").NavigateOptions & {
64
65
  locale?: string | undefined;
65
66
  }) | undefined): void;
66
- replace<Pathname_3 extends keyof PathnamesConfig>(href: HrefOrHrefWithParams<Pathname_3>, options?: (import("next/dist/shared/lib/app-router-context.shared-runtime").NavigateOptions & {
67
+ replace<Pathname_4 extends keyof PathnamesConfig>(href: HrefOrHrefWithParams<Pathname_4>, options?: (import("next/dist/shared/lib/app-router-context.shared-runtime").NavigateOptions & {
67
68
  locale?: string | undefined;
68
69
  }) | undefined): void;
69
- prefetch<Pathname_4 extends keyof PathnamesConfig>(href: HrefOrHrefWithParams<Pathname_4>, options?: (import("next/dist/shared/lib/app-router-context.shared-runtime").PrefetchOptions & {
70
+ prefetch<Pathname_5 extends keyof PathnamesConfig>(href: HrefOrHrefWithParams<Pathname_5>, options?: (import("next/dist/shared/lib/app-router-context.shared-runtime").PrefetchOptions & {
70
71
  locale?: string | undefined;
71
72
  }) | undefined): void;
72
73
  back(): void;
@@ -45,6 +45,7 @@ export default function createSharedPathnamesNavigation<Locales extends AllLocal
45
45
  ref?: React.Ref<HTMLAnchorElement> | undefined;
46
46
  }) => ReactElement;
47
47
  redirect: (pathname: string, type?: import("next/navigation").RedirectType | undefined) => never;
48
+ permanentRedirect: (pathname: string, type?: import("next/navigation").RedirectType | undefined) => never;
48
49
  usePathname: () => string;
49
50
  useRouter: typeof useBaseRouter;
50
51
  };
@@ -53,6 +53,7 @@ export default function createLocalizedPathnamesNavigation<Locales extends AllLo
53
53
  locale?: Locales[number] | undefined;
54
54
  }) => React.JSX.Element;
55
55
  redirect: <Pathname_1 extends keyof PathnamesConfig>(href: HrefOrHrefWithParams<Pathname_1>, type?: import("next/navigation").RedirectType | undefined) => never;
56
+ permanentRedirect: <Pathname_2 extends keyof PathnamesConfig>(href: HrefOrHrefWithParams<Pathname_2>, type?: import("next/navigation").RedirectType | undefined) => never;
56
57
  getPathname: ({ href, locale }: {
57
58
  locale: Locales[number];
58
59
  href: HrefOrHrefWithParams<keyof PathnamesConfig>;
@@ -7,6 +7,7 @@ export default function createSharedPathnamesNavigation<Locales extends AllLocal
7
7
  }): {
8
8
  Link: (props: ComponentProps<typeof ServerLink<Locales>>) => React.JSX.Element;
9
9
  redirect: (pathname: string, type?: import("next/navigation").RedirectType | undefined) => never;
10
+ permanentRedirect: (pathname: string, type?: import("next/navigation").RedirectType | undefined) => never;
10
11
  usePathname: () => never;
11
12
  useRouter: () => never;
12
13
  };
@@ -0,0 +1,6 @@
1
+ import { LocalePrefix, ParametersExceptFirst } from '../../shared/types';
2
+ import basePermanentRedirect from '../shared/basePermanentRedirect';
3
+ export default function serverPermanentRedirect(params: {
4
+ pathname: string;
5
+ localePrefix?: LocalePrefix;
6
+ }, ...args: ParametersExceptFirst<typeof basePermanentRedirect>): never;
@@ -0,0 +1,7 @@
1
+ import { permanentRedirect as nextPermanentRedirect } from 'next/navigation';
2
+ import { AllLocales, LocalePrefix, ParametersExceptFirst } from '../../shared/types';
3
+ export default function basePermanentRedirect(params: {
4
+ pathname: string;
5
+ locale: AllLocales[number];
6
+ localePrefix?: LocalePrefix;
7
+ }, ...args: ParametersExceptFirst<typeof nextPermanentRedirect>): never;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "3.6.0",
3
+ "version": "3.8.0",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "funding": [
@@ -82,7 +82,7 @@
82
82
  "dependencies": {
83
83
  "@formatjs/intl-localematcher": "^0.2.32",
84
84
  "negotiator": "^0.6.3",
85
- "use-intl": "^3.6.0"
85
+ "use-intl": "^3.8.0"
86
86
  },
87
87
  "peerDependencies": {
88
88
  "next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
@@ -114,19 +114,19 @@
114
114
  "size-limit": [
115
115
  {
116
116
  "path": "dist/production/index.react-client.js",
117
- "limit": "12.99 KB"
117
+ "limit": "13.055 KB"
118
118
  },
119
119
  {
120
120
  "path": "dist/production/index.react-server.js",
121
- "limit": "13.75 KB"
121
+ "limit": "13.765 KB"
122
122
  },
123
123
  {
124
124
  "path": "dist/production/navigation.react-client.js",
125
- "limit": "2.84 KB"
125
+ "limit": "2.89 KB"
126
126
  },
127
127
  {
128
128
  "path": "dist/production/navigation.react-server.js",
129
- "limit": "2.95 KB"
129
+ "limit": "3.01 KB"
130
130
  },
131
131
  {
132
132
  "path": "dist/production/server.react-client.js",
@@ -134,12 +134,12 @@
134
134
  },
135
135
  {
136
136
  "path": "dist/production/server.react-server.js",
137
- "limit": "12.945 KB"
137
+ "limit": "13.05 KB"
138
138
  },
139
139
  {
140
140
  "path": "dist/production/middleware.js",
141
141
  "limit": "5.81 KB"
142
142
  }
143
143
  ],
144
- "gitHead": "5cb950652a74f5bb1675d747d1140ec2e2f04f8a"
144
+ "gitHead": "5cc264ddd769a57ea09440f25c26325c142d0c25"
145
145
  }