next-intl 3.25.0 → 3.25.2

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.
@@ -56,7 +56,8 @@ options) {
56
56
  });
57
57
  }
58
58
  function redirect(url, redirectDomain) {
59
- const urlObj = new URL(utils$1.normalizeTrailingSlash(url), request.url);
59
+ const urlObj = new URL(url, request.url);
60
+ urlObj.pathname = utils$1.normalizeTrailingSlash(urlObj.pathname);
60
61
  if (domainsConfig.length > 0 && !redirectDomain && domain) {
61
62
  const bestMatchingDomain = utils.getBestMatchingDomain(domain, locale, domainsConfig);
62
63
  if (bestMatchingDomain) {
@@ -126,7 +126,7 @@ function createLocalizedPathnamesNavigation(routing) {
126
126
  }), [baseRouter, defaultLocale]);
127
127
  }
128
128
  function usePathname() {
129
- const pathname = useBasePathname.default(config$1.localePrefix);
129
+ const pathname = useBasePathname.default(config$1);
130
130
  const locale = useTypedLocale();
131
131
 
132
132
  // @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.
@@ -23,7 +23,7 @@ function createNavigation(routing) {
23
23
 
24
24
  /** @see https://next-intl-docs.vercel.app/docs/routing/navigation#usepathname */
25
25
  function usePathname() {
26
- const pathname = useBasePathname.default(config.localePrefix);
26
+ const pathname = useBasePathname.default(config);
27
27
  const locale = useTypedLocale();
28
28
 
29
29
  // @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.
@@ -48,7 +48,10 @@ function createSharedPathnamesNavigation(routing) {
48
48
  }, ...args);
49
49
  }
50
50
  function usePathname() {
51
- const result = useBasePathname.default(localePrefix);
51
+ const result = useBasePathname.default({
52
+ localePrefix,
53
+ defaultLocale: routing === null || routing === void 0 ? void 0 : routing.defaultLocale
54
+ });
52
55
  // @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.
53
56
  return result;
54
57
  }
@@ -7,7 +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
 
10
- function useBasePathname(localePrefix) {
10
+ function useBasePathname(config) {
11
11
  // The types aren't entirely correct here. Outside of Next.js
12
12
  // `useParams` can be called, but the return type is `null`.
13
13
 
@@ -21,11 +21,20 @@ function useBasePathname(localePrefix) {
21
21
  const locale = useLocale.default();
22
22
  return React.useMemo(() => {
23
23
  if (!pathname) return pathname;
24
- const prefix = utils.getLocalePrefix(locale, localePrefix);
24
+ let unlocalizedPathname = pathname;
25
+ const prefix = utils.getLocalePrefix(locale, config.localePrefix);
25
26
  const isPathnamePrefixed = utils.hasPathnamePrefixed(prefix, pathname);
26
- const unlocalizedPathname = isPathnamePrefixed ? utils.unprefixPathname(pathname, prefix) : pathname;
27
+ if (isPathnamePrefixed) {
28
+ unlocalizedPathname = utils.unprefixPathname(pathname, prefix);
29
+ } else if (config.localePrefix.mode === 'as-needed' && config.defaultLocale === locale && config.localePrefix.prefixes) {
30
+ // Workaround for https://github.com/vercel/next.js/issues/73085
31
+ const localeAsPrefix = utils.getLocaleAsPrefix(locale);
32
+ if (utils.hasPathnamePrefixed(localeAsPrefix, pathname)) {
33
+ unlocalizedPathname = utils.unprefixPathname(pathname, localeAsPrefix);
34
+ }
35
+ }
27
36
  return unlocalizedPathname;
28
- }, [locale, localePrefix, pathname]);
37
+ }, [config.defaultLocale, config.localePrefix, locale, pathname]);
29
38
  }
30
39
 
31
40
  exports.default = useBasePathname;
@@ -95,7 +95,10 @@ function getLocalePrefix(locale, localePrefix) {
95
95
  return localePrefix.mode !== 'never' && ((_localePrefix$prefixe = localePrefix.prefixes) === null || _localePrefix$prefixe === void 0 ? void 0 : _localePrefix$prefixe[locale]) ||
96
96
  // We return a prefix even if `mode: 'never'`. It's up to the consumer
97
97
  // to decide to use it or not.
98
- '/' + locale;
98
+ getLocaleAsPrefix(locale);
99
+ }
100
+ function getLocaleAsPrefix(locale) {
101
+ return '/' + locale;
99
102
  }
100
103
  function templateToRegex(template) {
101
104
  const regexPattern = template
@@ -154,6 +157,7 @@ function getSortedPathnames(pathnames) {
154
157
  return pathnames.sort(comparePathnamePairs);
155
158
  }
156
159
 
160
+ exports.getLocaleAsPrefix = getLocaleAsPrefix;
157
161
  exports.getLocalePrefix = getLocalePrefix;
158
162
  exports.getSortedPathnames = getSortedPathnames;
159
163
  exports.hasPathnamePrefixed = hasPathnamePrefixed;
@@ -1 +1 @@
1
- import{NextResponse as e}from"next/server";import{receiveRoutingConfig as o}from"../routing/config.js";import{HEADER_LOCALE_NAME as l}from"../shared/constants.js";import{matchesPathname as t,normalizeTrailingSlash as r,getLocalePrefix as a}from"../shared/utils.js";import n from"./getAlternateLinksHeaderValue.js";import i from"./resolveLocale.js";import s from"./syncCookie.js";import{sanitizePathname as c,isLocaleSupportedOnDomain as d,getNormalizedPathname as f,getPathnameMatch as m,getInternalTemplate as u,formatTemplatePathname as h,formatPathname as x,getBestMatchingDomain as v,applyBasePath as p,getLocaleAsPrefix as U}from"./utils.js";function P(P,k){var L,g,j;const w=o({...P,alternateLinks:null!==(L=null==k?void 0:k.alternateLinks)&&void 0!==L?L:P.alternateLinks,localeDetection:null!==(g=null==k?void 0:k.localeDetection)&&void 0!==g?g:P.localeDetection,localeCookie:null!==(j=null==k?void 0:k.localeCookie)&&void 0!==j?j:P.localeCookie});return function(o){var P;let k;try{k=decodeURI(o.nextUrl.pathname)}catch(o){return e.next()}const L=c(k),{domain:g,locale:j}=i(w,o.headers,o.cookies,L),C=g?g.defaultLocale===j:j===w.defaultLocale,b=(null===(P=w.domains)||void 0===P?void 0:P.filter((e=>d(j,e))))||[],y=null!=w.domains&&!g;function D(t){const r=new URL(t,o.url);o.nextUrl.basePath&&(r.pathname=p(r.pathname,o.nextUrl.basePath));const a=new Headers(o.headers);return a.set(l,j),e.rewrite(r,{request:{headers:a}})}function R(l,t){const a=new URL(r(l),o.url);if(b.length>0&&!t&&g){const e=v(g,j,b);e&&(t=e.domain,e.defaultLocale===j&&"as-needed"===w.localePrefix.mode&&(a.pathname=f(a.pathname,w.locales,w.localePrefix)))}var n,i;t&&(a.host=t,o.headers.get("x-forwarded-host")&&(a.protocol=null!==(n=o.headers.get("x-forwarded-proto"))&&void 0!==n?n:o.nextUrl.protocol,a.port=null!==(i=o.headers.get("x-forwarded-port"))&&void 0!==i?i:""));return o.nextUrl.basePath&&(a.pathname=p(a.pathname,o.nextUrl.basePath)),e.redirect(a.toString())}const q=f(L,w.locales,w.localePrefix),H=m(L,w.locales,w.localePrefix),z=null!=H,A="never"===w.localePrefix.mode||C&&"as-needed"===w.localePrefix.mode;let I,S,V=q;const B=w.pathnames;if(B){let e;if([e,S]=u(B,q,j),S){const l=B[S],r="string"==typeof l?l:l[j];if(t(r,q))V=h(q,r,S);else{let t;t=e?"string"==typeof l?l:l[e]:S;const n=A?void 0:a(j,w.localePrefix),i=h(q,t,r);I=R(x(i,n,o.nextUrl.search))}}}if(!I)if("/"!==V||z){const e=x(V,U(j),o.nextUrl.search);if(z){const l=x(q,H.prefix,o.nextUrl.search);if("never"===w.localePrefix.mode)I=R(x(q,void 0,o.nextUrl.search));else if(H.exact)if(C&&A)I=R(x(q,void 0,o.nextUrl.search));else if(w.domains){const o=v(g,H.locale,b);I=(null==g?void 0:g.domain)===(null==o?void 0:o.domain)||y?D(e):R(l,null==o?void 0:o.domain)}else I=D(e);else I=R(l)}else I=A?D(e):R(x(q,a(j,w.localePrefix),o.nextUrl.search))}else I=A?D(x(V,U(j),o.nextUrl.search)):R(x(q,a(j,w.localePrefix),o.nextUrl.search));return w.localeDetection&&w.localeCookie&&s(o,I,j,w.localeCookie),"never"!==w.localePrefix.mode&&w.alternateLinks&&w.locales.length>1&&I.headers.set("Link",n({routing:w,localizedPathnames:null!=S&&B?B[S]:void 0,request:o,resolvedLocale:j})),I}}export{P as default};
1
+ import{NextResponse as e}from"next/server";import{receiveRoutingConfig as o}from"../routing/config.js";import{HEADER_LOCALE_NAME as l}from"../shared/constants.js";import{matchesPathname as t,normalizeTrailingSlash as a,getLocalePrefix as r}from"../shared/utils.js";import n from"./getAlternateLinksHeaderValue.js";import i from"./resolveLocale.js";import s from"./syncCookie.js";import{sanitizePathname as c,isLocaleSupportedOnDomain as d,getNormalizedPathname as f,getPathnameMatch as m,getInternalTemplate as h,formatTemplatePathname as u,formatPathname as x,getBestMatchingDomain as p,applyBasePath as v,getLocaleAsPrefix as U}from"./utils.js";function P(P,k){var L,g,j;const w=o({...P,alternateLinks:null!==(L=null==k?void 0:k.alternateLinks)&&void 0!==L?L:P.alternateLinks,localeDetection:null!==(g=null==k?void 0:k.localeDetection)&&void 0!==g?g:P.localeDetection,localeCookie:null!==(j=null==k?void 0:k.localeCookie)&&void 0!==j?j:P.localeCookie});return function(o){var P;let k;try{k=decodeURI(o.nextUrl.pathname)}catch(o){return e.next()}const L=c(k),{domain:g,locale:j}=i(w,o.headers,o.cookies,L),C=g?g.defaultLocale===j:j===w.defaultLocale,b=(null===(P=w.domains)||void 0===P?void 0:P.filter((e=>d(j,e))))||[],y=null!=w.domains&&!g;function D(t){const a=new URL(t,o.url);o.nextUrl.basePath&&(a.pathname=v(a.pathname,o.nextUrl.basePath));const r=new Headers(o.headers);return r.set(l,j),e.rewrite(a,{request:{headers:r}})}function R(l,t){const r=new URL(l,o.url);if(r.pathname=a(r.pathname),b.length>0&&!t&&g){const e=p(g,j,b);e&&(t=e.domain,e.defaultLocale===j&&"as-needed"===w.localePrefix.mode&&(r.pathname=f(r.pathname,w.locales,w.localePrefix)))}var n,i;t&&(r.host=t,o.headers.get("x-forwarded-host")&&(r.protocol=null!==(n=o.headers.get("x-forwarded-proto"))&&void 0!==n?n:o.nextUrl.protocol,r.port=null!==(i=o.headers.get("x-forwarded-port"))&&void 0!==i?i:""));return o.nextUrl.basePath&&(r.pathname=v(r.pathname,o.nextUrl.basePath)),e.redirect(r.toString())}const q=f(L,w.locales,w.localePrefix),H=m(L,w.locales,w.localePrefix),z=null!=H,A="never"===w.localePrefix.mode||C&&"as-needed"===w.localePrefix.mode;let I,S,V=q;const B=w.pathnames;if(B){let e;if([e,S]=h(B,q,j),S){const l=B[S],a="string"==typeof l?l:l[j];if(t(a,q))V=u(q,a,S);else{let t;t=e?"string"==typeof l?l:l[e]:S;const n=A?void 0:r(j,w.localePrefix),i=u(q,t,a);I=R(x(i,n,o.nextUrl.search))}}}if(!I)if("/"!==V||z){const e=x(V,U(j),o.nextUrl.search);if(z){const l=x(q,H.prefix,o.nextUrl.search);if("never"===w.localePrefix.mode)I=R(x(q,void 0,o.nextUrl.search));else if(H.exact)if(C&&A)I=R(x(q,void 0,o.nextUrl.search));else if(w.domains){const o=p(g,H.locale,b);I=(null==g?void 0:g.domain)===(null==o?void 0:o.domain)||y?D(e):R(l,null==o?void 0:o.domain)}else I=D(e);else I=R(l)}else I=A?D(e):R(x(q,r(j,w.localePrefix),o.nextUrl.search))}else I=A?D(x(V,U(j),o.nextUrl.search)):R(x(q,r(j,w.localePrefix),o.nextUrl.search));return w.localeDetection&&w.localeCookie&&s(o,I,j,w.localeCookie),"never"!==w.localePrefix.mode&&w.alternateLinks&&w.locales.length>1&&I.headers.set("Link",n({routing:w,localizedPathnames:null!=S&&B?B[S]:void 0,request:o,resolvedLocale:j})),I}}export{P as default};
@@ -1 +1 @@
1
- import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as o,useMemo as t}from"react";import n from"../../react-client/useLocale.js";import{receiveRoutingConfig as a,receiveLocaleCookie as l}from"../../routing/config.js";import{getRoute as c,compileLocalizedPathname as i,normalizeNameOrNameWithParams as s}from"../shared/utils.js";import f from"./ClientLink.js";import{clientRedirect as u,clientPermanentRedirect as m}from"./redirects.js";import h from"./useBasePathname.js";import p from"./useBaseRouter.js";function d(d){const v=a(d),P=l(d.localeCookie);function x(){const e=n();if(!v.locales.includes(e))throw new Error('Unknown locale encountered: "'.concat(e,'". Make sure to validate the locale in `i18n.ts`.'));return e}function g(o,t){let{href:n,locale:a,...l}=o;const c=x(),s=a||c;return r.createElement(f,e({ref:t,href:i({locale:s,pathname:n,params:"object"==typeof n?n.params:void 0,pathnames:v.pathnames}),locale:a,localeCookie:P,localePrefix:v.localePrefix},l))}const j=o(g);function w(e){let{href:r,locale:o}=e;return i({...s(r),locale:o,pathnames:v.pathnames})}return j.displayName="Link",{Link:j,redirect:function(e){const r=w({href:e,locale:x()});for(var o=arguments.length,t=new Array(o>1?o-1:0),n=1;n<o;n++)t[n-1]=arguments[n];return u({pathname:r,localePrefix:v.localePrefix},...t)},permanentRedirect:function(e){const r=w({href:e,locale:x()});for(var o=arguments.length,t=new Array(o>1?o-1:0),n=1;n<o;n++)t[n-1]=arguments[n];return m({pathname:r,localePrefix:v.localePrefix},...t)},usePathname:function(){const e=h(v.localePrefix),r=x();return t((()=>e?c(r,e,v.pathnames):e),[r,e])},useRouter:function(){const e=p(v.localePrefix,P),r=x();return t((()=>({...e,push(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=w({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.push(c,...a)},replace(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=w({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.replace(c,...a)},prefetch(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=w({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.prefetch(c,...a)}})),[e,r])},getPathname:w}}export{d as default};
1
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as o,useMemo as t}from"react";import n from"../../react-client/useLocale.js";import{receiveRoutingConfig as a,receiveLocaleCookie as l}from"../../routing/config.js";import{getRoute as c,compileLocalizedPathname as i,normalizeNameOrNameWithParams as s}from"../shared/utils.js";import f from"./ClientLink.js";import{clientRedirect as u,clientPermanentRedirect as m}from"./redirects.js";import h from"./useBasePathname.js";import p from"./useBaseRouter.js";function d(d){const v=a(d),P=l(d.localeCookie);function g(){const e=n();if(!v.locales.includes(e))throw new Error('Unknown locale encountered: "'.concat(e,'". Make sure to validate the locale in `i18n.ts`.'));return e}function j(o,t){let{href:n,locale:a,...l}=o;const c=g(),s=a||c;return r.createElement(f,e({ref:t,href:i({locale:s,pathname:n,params:"object"==typeof n?n.params:void 0,pathnames:v.pathnames}),locale:a,localeCookie:P,localePrefix:v.localePrefix},l))}const x=o(j);function w(e){let{href:r,locale:o}=e;return i({...s(r),locale:o,pathnames:v.pathnames})}return x.displayName="Link",{Link:x,redirect:function(e){const r=w({href:e,locale:g()});for(var o=arguments.length,t=new Array(o>1?o-1:0),n=1;n<o;n++)t[n-1]=arguments[n];return u({pathname:r,localePrefix:v.localePrefix},...t)},permanentRedirect:function(e){const r=w({href:e,locale:g()});for(var o=arguments.length,t=new Array(o>1?o-1:0),n=1;n<o;n++)t[n-1]=arguments[n];return m({pathname:r,localePrefix:v.localePrefix},...t)},usePathname:function(){const e=h(v),r=g();return t((()=>e?c(r,e,v.pathnames):e),[r,e])},useRouter:function(){const e=p(v.localePrefix,P),r=g();return t((()=>({...e,push(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=w({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.push(c,...a)},replace(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=w({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.replace(c,...a)},prefetch(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=w({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.prefetch(c,...a)}})),[e,r])},getPathname:w}}export{d as default};
@@ -1 +1 @@
1
- import{useRouter as e,usePathname as t}from"next/navigation";import{useMemo as o}from"react";import n from"../../react-client/useLocale.js";import r from"../shared/createSharedNavigationFns.js";import a from"../shared/syncLocaleCookie.js";import{getRoute as c}from"../shared/utils.js";import i from"./useBasePathname.js";function s(s){function u(){return n()}const{Link:m,config:f,getPathname:h,...l}=r(u,s);return{...l,Link:m,usePathname:function(){const e=i(f.localePrefix),t=u();return o((()=>e&&f.pathnames?c(t,e,f.pathnames):e),[t,e])},useRouter:function(){const n=e(),r=u(),c=t();return o((()=>{function e(e){return function(t,o){const{locale:n,...i}=o||{},s=[h({href:t,locale:n||r,domain:window.location.host})];Object.keys(i).length>0&&s.push(i),e(...s),a(f.localeCookie,c,r,n)}}return{...n,push:e(n.push),replace:e(n.replace),prefetch:e(n.prefetch)}}),[r,c,n])},getPathname:h}}export{s as default};
1
+ import{useRouter as e,usePathname as t}from"next/navigation";import{useMemo as o}from"react";import n from"../../react-client/useLocale.js";import r from"../shared/createSharedNavigationFns.js";import a from"../shared/syncLocaleCookie.js";import{getRoute as s}from"../shared/utils.js";import c from"./useBasePathname.js";function i(i){function u(){return n()}const{Link:m,config:f,getPathname:h,...p}=r(u,i);return{...p,Link:m,usePathname:function(){const e=c(f),t=u();return o((()=>e&&f.pathnames?s(t,e,f.pathnames):e),[t,e])},useRouter:function(){const n=e(),r=u(),s=t();return o((()=>{function e(e){return function(t,o){const{locale:n,...c}=o||{},i=[h({href:t,locale:n||r,domain:window.location.host})];Object.keys(c).length>0&&i.push(c),e(...i),a(f.localeCookie,s,r,n)}}return{...n,push:e(n.push),replace:e(n.replace),prefetch:e(n.prefetch)}}),[r,s,n])},getPathname:h}}export{i as default};
@@ -1 +1 @@
1
- import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as o}from"react";import{receiveLocalePrefixConfig as t,receiveLocaleCookie as n}from"../../routing/config.js";import i from"./ClientLink.js";import{clientRedirect as a,clientPermanentRedirect as l}from"./redirects.js";import u from"./useBasePathname.js";import f from"./useBaseRouter.js";function m(m){const c=t(null==m?void 0:m.localePrefix),s=n(null==m?void 0:m.localeCookie);function p(o,t){return r.createElement(i,e({ref:t,localeCookie:s,localePrefix:c},o))}const d=o(p);return d.displayName="Link",{Link:d,redirect:function(e){for(var r=arguments.length,o=new Array(r>1?r-1:0),t=1;t<r;t++)o[t-1]=arguments[t];return a({pathname:e,localePrefix:c},...o)},permanentRedirect:function(e){for(var r=arguments.length,o=new Array(r>1?r-1:0),t=1;t<r;t++)o[t-1]=arguments[t];return l({pathname:e,localePrefix:c},...o)},usePathname:function(){return u(c)},useRouter:function(){return f(c,s)}}}export{m as default};
1
+ import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as o}from"react";import{receiveLocalePrefixConfig as t,receiveLocaleCookie as n}from"../../routing/config.js";import l from"./ClientLink.js";import{clientRedirect as a,clientPermanentRedirect as i}from"./redirects.js";import u from"./useBasePathname.js";import f from"./useBaseRouter.js";function c(c){const m=t(null==c?void 0:c.localePrefix),s=n(null==c?void 0:c.localeCookie);function p(o,t){return r.createElement(l,e({ref:t,localeCookie:s,localePrefix:m},o))}const d=o(p);return d.displayName="Link",{Link:d,redirect:function(e){for(var r=arguments.length,o=new Array(r>1?r-1:0),t=1;t<r;t++)o[t-1]=arguments[t];return a({pathname:e,localePrefix:m},...o)},permanentRedirect:function(e){for(var r=arguments.length,o=new Array(r>1?r-1:0),t=1;t<r;t++)o[t-1]=arguments[t];return i({pathname:e,localePrefix:m},...o)},usePathname:function(){return u({localePrefix:m,defaultLocale:null==c?void 0:c.defaultLocale})},useRouter:function(){return f(m,s)}}}export{c as default};
@@ -1 +1 @@
1
- import{usePathname as r}from"next/navigation";import{useMemo as t}from"react";import o from"../../react-client/useLocale.js";import{hasPathnamePrefixed as e,unprefixPathname as n,getLocalePrefix as i}from"../../shared/utils.js";function a(a){const m=r(),s=o();return t((()=>{if(!m)return m;const r=i(s,a);return e(r,m)?n(m,r):m}),[s,a,m])}export{a as default};
1
+ import{usePathname as e}from"next/navigation";import{useMemo as r}from"react";import o from"../../react-client/useLocale.js";import{hasPathnamePrefixed as t,unprefixPathname as l,getLocalePrefix as a,getLocaleAsPrefix as i}from"../../shared/utils.js";function f(f){const c=e(),n=o();return r((()=>{if(!c)return c;let e=c;const r=a(n,f.localePrefix);if(t(r,c))e=l(c,r);else if("as-needed"===f.localePrefix.mode&&f.defaultLocale===n&&f.localePrefix.prefixes){const r=i(n);t(r,c)&&(e=l(c,r))}return e}),[f.defaultLocale,f.localePrefix,n,c])}export{f as default};
@@ -1 +1 @@
1
- function n(n){return function(n){return"object"==typeof n?null==n.host&&null==n.hostname:!/^[a-z]+:/i.test(n)}(n)&&!function(n){const t="object"==typeof n?n.pathname:n;return null!=t&&!t.startsWith("/")}(n)}function t(t,r){let u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:r,c=arguments.length>3?arguments[3]:void 0,o=arguments.length>4?arguments[4]:void 0;if(!n(t))return t;const f=r!==u,l=i(o,c);return(f||l)&&null!=o?e(t,o):t}function e(n,t){let e;return"string"==typeof n?e=u(t,n):(e={...n},n.pathname&&(e.pathname=u(t,n.pathname))),e}function r(n,t){return n.replace(new RegExp("^".concat(t)),"")||"/"}function u(n,t){let e=n;return/^\/(\?.*)?$/.test(t)&&(t=t.slice(1)),e+=t,e}function i(n,t){return t===n||t.startsWith("".concat(n,"/"))}function c(n){const t=function(){try{return"true"===process.env._next_intl_trailing_slash}catch(n){return!1}}();if("/"!==n){const e=n.endsWith("/");t&&!e?n+="/":!t&&e&&(n=n.slice(0,-1))}return n}function o(n,t){const e=c(n),r=c(t);return l(e).test(r)}function f(n,t){var e;return"never"!==t.mode&&(null===(e=t.prefixes)||void 0===e?void 0:e[n])||"/"+n}function l(n){const t=n.replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp("^".concat(t,"$"))}function s(n){return n.includes("[[...")}function a(n){return n.includes("[...")}function p(n){return n.includes("[")}function h(n,t){const e=n.split("/"),r=t.split("/"),u=Math.max(e.length,r.length);for(let n=0;n<u;n++){const t=e[n],u=r[n];if(!t&&u)return-1;if(t&&!u)return 1;if(t||u){if(!p(t)&&p(u))return-1;if(p(t)&&!p(u))return 1;if(!a(t)&&a(u))return-1;if(a(t)&&!a(u))return 1;if(!s(t)&&s(u))return-1;if(s(t)&&!s(u))return 1}}return 0}function g(n){return n.sort(h)}export{f as getLocalePrefix,g as getSortedPathnames,i as hasPathnamePrefixed,n as isLocalizableHref,t as localizeHref,o as matchesPathname,c as normalizeTrailingSlash,e as prefixHref,u as prefixPathname,l as templateToRegex,r as unprefixPathname};
1
+ function n(n){return function(n){return"object"==typeof n?null==n.host&&null==n.hostname:!/^[a-z]+:/i.test(n)}(n)&&!function(n){const t="object"==typeof n?n.pathname:n;return null!=t&&!t.startsWith("/")}(n)}function t(t,r){let u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:r,c=arguments.length>3?arguments[3]:void 0,o=arguments.length>4?arguments[4]:void 0;if(!n(t))return t;const f=r!==u,l=i(o,c);return(f||l)&&null!=o?e(t,o):t}function e(n,t){let e;return"string"==typeof n?e=u(t,n):(e={...n},n.pathname&&(e.pathname=u(t,n.pathname))),e}function r(n,t){return n.replace(new RegExp("^".concat(t)),"")||"/"}function u(n,t){let e=n;return/^\/(\?.*)?$/.test(t)&&(t=t.slice(1)),e+=t,e}function i(n,t){return t===n||t.startsWith("".concat(n,"/"))}function c(n){const t=function(){try{return"true"===process.env._next_intl_trailing_slash}catch(n){return!1}}();if("/"!==n){const e=n.endsWith("/");t&&!e?n+="/":!t&&e&&(n=n.slice(0,-1))}return n}function o(n,t){const e=c(n),r=c(t);return s(e).test(r)}function f(n,t){var e;return"never"!==t.mode&&(null===(e=t.prefixes)||void 0===e?void 0:e[n])||l(n)}function l(n){return"/"+n}function s(n){const t=n.replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp("^".concat(t,"$"))}function a(n){return n.includes("[[...")}function p(n){return n.includes("[...")}function h(n){return n.includes("[")}function g(n,t){const e=n.split("/"),r=t.split("/"),u=Math.max(e.length,r.length);for(let n=0;n<u;n++){const t=e[n],u=r[n];if(!t&&u)return-1;if(t&&!u)return 1;if(t||u){if(!h(t)&&h(u))return-1;if(h(t)&&!h(u))return 1;if(!p(t)&&p(u))return-1;if(p(t)&&!p(u))return 1;if(!a(t)&&a(u))return-1;if(a(t)&&!a(u))return 1}}return 0}function d(n){return n.sort(g)}export{l as getLocaleAsPrefix,f as getLocalePrefix,d as getSortedPathnames,i as hasPathnamePrefixed,n as isLocalizableHref,t as localizeHref,o as matchesPathname,c as normalizeTrailingSlash,e as prefixHref,u as prefixPathname,s as templateToRegex,r as unprefixPathname};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/server"),a=require("../routing/config.js"),t=require("../shared/constants.js"),l=require("../shared/utils.js"),o=require("./getAlternateLinksHeaderValue.js"),n=require("./resolveLocale.js"),r=require("./syncCookie.js"),i=require("./utils.js");exports.default=function(s,c){var d,f,h;const m=a.receiveRoutingConfig({...s,alternateLinks:null!==(d=null==c?void 0:c.alternateLinks)&&void 0!==d?d:s.alternateLinks,localeDetection:null!==(f=null==c?void 0:c.localeDetection)&&void 0!==f?f:s.localeDetection,localeCookie:null!==(h=null==c?void 0:c.localeCookie)&&void 0!==h?h:s.localeCookie});return function(a){var s;let c;try{c=decodeURI(a.nextUrl.pathname)}catch(a){return e.NextResponse.next()}const d=i.sanitizePathname(c),{domain:f,locale:h}=n.default(m,a.headers,a.cookies,d),u=f?f.defaultLocale===h:h===m.defaultLocale,x=(null===(s=m.domains)||void 0===s?void 0:s.filter((e=>i.isLocaleSupportedOnDomain(h,e))))||[],P=null!=m.domains&&!f;function p(l){const o=new URL(l,a.url);a.nextUrl.basePath&&(o.pathname=i.applyBasePath(o.pathname,a.nextUrl.basePath));const n=new Headers(a.headers);return n.set(t.HEADER_LOCALE_NAME,h),e.NextResponse.rewrite(o,{request:{headers:n}})}function v(t,o){const n=new URL(l.normalizeTrailingSlash(t),a.url);if(x.length>0&&!o&&f){const e=i.getBestMatchingDomain(f,h,x);e&&(o=e.domain,e.defaultLocale===h&&"as-needed"===m.localePrefix.mode&&(n.pathname=i.getNormalizedPathname(n.pathname,m.locales,m.localePrefix)))}var r,s;o&&(n.host=o,a.headers.get("x-forwarded-host")&&(n.protocol=null!==(r=a.headers.get("x-forwarded-proto"))&&void 0!==r?r:a.nextUrl.protocol,n.port=null!==(s=a.headers.get("x-forwarded-port"))&&void 0!==s?s:""));return a.nextUrl.basePath&&(n.pathname=i.applyBasePath(n.pathname,a.nextUrl.basePath)),e.NextResponse.redirect(n.toString())}const g=i.getNormalizedPathname(d,m.locales,m.localePrefix),L=i.getPathnameMatch(d,m.locales,m.localePrefix),U=null!=L,k="never"===m.localePrefix.mode||u&&"as-needed"===m.localePrefix.mode;let q,j,C=g;const D=m.pathnames;if(D){let e;if([e,j]=i.getInternalTemplate(D,g,h),j){const t=D[j],o="string"==typeof t?t:t[h];if(l.matchesPathname(o,g))C=i.formatTemplatePathname(g,o,j);else{let n;n=e?"string"==typeof t?t:t[e]:j;const r=k?void 0:l.getLocalePrefix(h,m.localePrefix),s=i.formatTemplatePathname(g,n,o);q=v(i.formatPathname(s,r,a.nextUrl.search))}}}if(!q)if("/"!==C||U){const e=i.formatPathname(C,i.getLocaleAsPrefix(h),a.nextUrl.search);if(U){const t=i.formatPathname(g,L.prefix,a.nextUrl.search);if("never"===m.localePrefix.mode)q=v(i.formatPathname(g,void 0,a.nextUrl.search));else if(L.exact)if(u&&k)q=v(i.formatPathname(g,void 0,a.nextUrl.search));else if(m.domains){const a=i.getBestMatchingDomain(f,L.locale,x);q=(null==f?void 0:f.domain)===(null==a?void 0:a.domain)||P?p(e):v(t,null==a?void 0:a.domain)}else q=p(e);else q=v(t)}else q=k?p(e):v(i.formatPathname(g,l.getLocalePrefix(h,m.localePrefix),a.nextUrl.search))}else q=k?p(i.formatPathname(C,i.getLocaleAsPrefix(h),a.nextUrl.search)):v(i.formatPathname(g,l.getLocalePrefix(h,m.localePrefix),a.nextUrl.search));return m.localeDetection&&m.localeCookie&&r.default(a,q,h,m.localeCookie),"never"!==m.localePrefix.mode&&m.alternateLinks&&m.locales.length>1&&q.headers.set("Link",o.default({routing:m,localizedPathnames:null!=j&&D?D[j]:void 0,request:a,resolvedLocale:h})),q}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/server"),a=require("../routing/config.js"),t=require("../shared/constants.js"),l=require("../shared/utils.js"),o=require("./getAlternateLinksHeaderValue.js"),n=require("./resolveLocale.js"),r=require("./syncCookie.js"),i=require("./utils.js");exports.default=function(s,c){var d,h,m;const f=a.receiveRoutingConfig({...s,alternateLinks:null!==(d=null==c?void 0:c.alternateLinks)&&void 0!==d?d:s.alternateLinks,localeDetection:null!==(h=null==c?void 0:c.localeDetection)&&void 0!==h?h:s.localeDetection,localeCookie:null!==(m=null==c?void 0:c.localeCookie)&&void 0!==m?m:s.localeCookie});return function(a){var s;let c;try{c=decodeURI(a.nextUrl.pathname)}catch(a){return e.NextResponse.next()}const d=i.sanitizePathname(c),{domain:h,locale:m}=n.default(f,a.headers,a.cookies,d),u=h?h.defaultLocale===m:m===f.defaultLocale,x=(null===(s=f.domains)||void 0===s?void 0:s.filter((e=>i.isLocaleSupportedOnDomain(m,e))))||[],P=null!=f.domains&&!h;function p(l){const o=new URL(l,a.url);a.nextUrl.basePath&&(o.pathname=i.applyBasePath(o.pathname,a.nextUrl.basePath));const n=new Headers(a.headers);return n.set(t.HEADER_LOCALE_NAME,m),e.NextResponse.rewrite(o,{request:{headers:n}})}function v(t,o){const n=new URL(t,a.url);if(n.pathname=l.normalizeTrailingSlash(n.pathname),x.length>0&&!o&&h){const e=i.getBestMatchingDomain(h,m,x);e&&(o=e.domain,e.defaultLocale===m&&"as-needed"===f.localePrefix.mode&&(n.pathname=i.getNormalizedPathname(n.pathname,f.locales,f.localePrefix)))}var r,s;o&&(n.host=o,a.headers.get("x-forwarded-host")&&(n.protocol=null!==(r=a.headers.get("x-forwarded-proto"))&&void 0!==r?r:a.nextUrl.protocol,n.port=null!==(s=a.headers.get("x-forwarded-port"))&&void 0!==s?s:""));return a.nextUrl.basePath&&(n.pathname=i.applyBasePath(n.pathname,a.nextUrl.basePath)),e.NextResponse.redirect(n.toString())}const g=i.getNormalizedPathname(d,f.locales,f.localePrefix),L=i.getPathnameMatch(d,f.locales,f.localePrefix),U=null!=L,k="never"===f.localePrefix.mode||u&&"as-needed"===f.localePrefix.mode;let q,j,C=g;const D=f.pathnames;if(D){let e;if([e,j]=i.getInternalTemplate(D,g,m),j){const t=D[j],o="string"==typeof t?t:t[m];if(l.matchesPathname(o,g))C=i.formatTemplatePathname(g,o,j);else{let n;n=e?"string"==typeof t?t:t[e]:j;const r=k?void 0:l.getLocalePrefix(m,f.localePrefix),s=i.formatTemplatePathname(g,n,o);q=v(i.formatPathname(s,r,a.nextUrl.search))}}}if(!q)if("/"!==C||U){const e=i.formatPathname(C,i.getLocaleAsPrefix(m),a.nextUrl.search);if(U){const t=i.formatPathname(g,L.prefix,a.nextUrl.search);if("never"===f.localePrefix.mode)q=v(i.formatPathname(g,void 0,a.nextUrl.search));else if(L.exact)if(u&&k)q=v(i.formatPathname(g,void 0,a.nextUrl.search));else if(f.domains){const a=i.getBestMatchingDomain(h,L.locale,x);q=(null==h?void 0:h.domain)===(null==a?void 0:a.domain)||P?p(e):v(t,null==a?void 0:a.domain)}else q=p(e);else q=v(t)}else q=k?p(e):v(i.formatPathname(g,l.getLocalePrefix(m,f.localePrefix),a.nextUrl.search))}else q=k?p(i.formatPathname(C,i.getLocaleAsPrefix(m),a.nextUrl.search)):v(i.formatPathname(g,l.getLocalePrefix(m,f.localePrefix),a.nextUrl.search));return f.localeDetection&&f.localeCookie&&r.default(a,q,m,f.localeCookie),"never"!==f.localePrefix.mode&&f.alternateLinks&&f.locales.length>1&&q.headers.set("Link",o.default({routing:f,localizedPathnames:null!=j&&D?D[j]:void 0,request:a,resolvedLocale:m})),q}};
@@ -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("../../routing/config.js"),l=require("../shared/utils.js"),o=require("./ClientLink.js"),n=require("./redirects.js"),c=require("./useBasePathname.js"),i=require("./useBaseRouter.js");function u(e){return e&&e.__esModule?e:{default:e}}var s=u(r);exports.default=function(u){const f=t.receiveRoutingConfig(u),h=t.receiveLocaleCookie(u.localeCookie);function d(){const e=a.default();if(!f.locales.includes(e))throw new Error(void 0);return e}function m(r,a){let{href:t,locale:n,...c}=r;const i=d(),u=n||i;return s.default.createElement(o.default,e.extends({ref:a,href:l.compileLocalizedPathname({locale:u,pathname:t,params:"object"==typeof t?t.params:void 0,pathnames:f.pathnames}),locale:n,localeCookie:h,localePrefix:f.localePrefix},c))}const p=r.forwardRef(m);function v(e){let{href:r,locale:a}=e;return l.compileLocalizedPathname({...l.normalizeNameOrNameWithParams(r),locale:a,pathnames:f.pathnames})}return p.displayName="Link",{Link:p,redirect:function(e){const r=v({href:e,locale:d()});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.clientRedirect({pathname:r,localePrefix:f.localePrefix},...t)},permanentRedirect:function(e){const r=v({href:e,locale:d()});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.clientPermanentRedirect({pathname:r,localePrefix:f.localePrefix},...t)},usePathname:function(){const e=c.default(f.localePrefix),a=d();return r.useMemo((()=>e?l.getRoute(a,e,f.pathnames):e),[a,e])},useRouter:function(){const e=i.default(f.localePrefix,h),a=d();return r.useMemo((()=>({...e,push(r){for(var t,l=arguments.length,o=new Array(l>1?l-1:0),n=1;n<l;n++)o[n-1]=arguments[n];const c=v({href:r,locale:(null===(t=o[0])||void 0===t?void 0:t.locale)||a});return e.push(c,...o)},replace(r){for(var t,l=arguments.length,o=new Array(l>1?l-1:0),n=1;n<l;n++)o[n-1]=arguments[n];const c=v({href:r,locale:(null===(t=o[0])||void 0===t?void 0:t.locale)||a});return e.replace(c,...o)},prefetch(r){for(var t,l=arguments.length,o=new Array(l>1?l-1:0),n=1;n<l;n++)o[n-1]=arguments[n];const c=v({href:r,locale:(null===(t=o[0])||void 0===t?void 0:t.locale)||a});return e.prefetch(c,...o)}})),[e,a])},getPathname:v}};
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("../../routing/config.js"),l=require("../shared/utils.js"),n=require("./ClientLink.js"),o=require("./redirects.js"),c=require("./useBasePathname.js"),i=require("./useBaseRouter.js");function u(e){return e&&e.__esModule?e:{default:e}}var s=u(r);exports.default=function(u){const f=t.receiveRoutingConfig(u),h=t.receiveLocaleCookie(u.localeCookie);function d(){const e=a.default();if(!f.locales.includes(e))throw new Error(void 0);return e}function m(r,a){let{href:t,locale:o,...c}=r;const i=d(),u=o||i;return s.default.createElement(n.default,e.extends({ref:a,href:l.compileLocalizedPathname({locale:u,pathname:t,params:"object"==typeof t?t.params:void 0,pathnames:f.pathnames}),locale:o,localeCookie:h,localePrefix:f.localePrefix},c))}const p=r.forwardRef(m);function v(e){let{href:r,locale:a}=e;return l.compileLocalizedPathname({...l.normalizeNameOrNameWithParams(r),locale:a,pathnames:f.pathnames})}return p.displayName="Link",{Link:p,redirect:function(e){const r=v({href:e,locale:d()});for(var a=arguments.length,t=new Array(a>1?a-1:0),l=1;l<a;l++)t[l-1]=arguments[l];return o.clientRedirect({pathname:r,localePrefix:f.localePrefix},...t)},permanentRedirect:function(e){const r=v({href:e,locale:d()});for(var a=arguments.length,t=new Array(a>1?a-1:0),l=1;l<a;l++)t[l-1]=arguments[l];return o.clientPermanentRedirect({pathname:r,localePrefix:f.localePrefix},...t)},usePathname:function(){const e=c.default(f),a=d();return r.useMemo((()=>e?l.getRoute(a,e,f.pathnames):e),[a,e])},useRouter:function(){const e=i.default(f.localePrefix,h),a=d();return r.useMemo((()=>({...e,push(r){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 c=v({href:r,locale:(null===(t=n[0])||void 0===t?void 0:t.locale)||a});return e.push(c,...n)},replace(r){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 c=v({href:r,locale:(null===(t=n[0])||void 0===t?void 0:t.locale)||a});return e.replace(c,...n)},prefetch(r){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 c=v({href:r,locale:(null===(t=n[0])||void 0===t?void 0:t.locale)||a});return e.prefetch(c,...n)}})),[e,a])},getPathname:v}};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/navigation"),t=require("react"),r=require("../../react-client/useLocale.js"),n=require("../shared/createSharedNavigationFns.js"),a=require("../shared/syncLocaleCookie.js"),u=require("../shared/utils.js"),o=require("./useBasePathname.js");exports.default=function(s){function c(){return r.default()}const{Link:i,config:l,getPathname:h,...f}=n.default(c,s);return{...f,Link:i,usePathname:function(){const e=o.default(l.localePrefix),r=c();return t.useMemo((()=>e&&l.pathnames?u.getRoute(r,e,l.pathnames):e),[r,e])},useRouter:function(){const r=e.useRouter(),n=c(),u=e.usePathname();return t.useMemo((()=>{function e(e){return function(t,r){const{locale:o,...s}=r||{},c=[h({href:t,locale:o||n,domain:window.location.host})];Object.keys(s).length>0&&c.push(s),e(...c),a.default(l.localeCookie,u,n,o)}}return{...r,push:e(r.push),replace:e(r.replace),prefetch:e(r.prefetch)}}),[n,u,r])},getPathname:h}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/navigation"),t=require("react"),r=require("../../react-client/useLocale.js"),n=require("../shared/createSharedNavigationFns.js"),a=require("../shared/syncLocaleCookie.js"),u=require("../shared/utils.js"),o=require("./useBasePathname.js");exports.default=function(s){function c(){return r.default()}const{Link:i,config:l,getPathname:h,...f}=n.default(c,s);return{...f,Link:i,usePathname:function(){const e=o.default(l),r=c();return t.useMemo((()=>e&&l.pathnames?u.getRoute(r,e,l.pathnames):e),[r,e])},useRouter:function(){const r=e.useRouter(),n=c(),u=e.usePathname();return t.useMemo((()=>{function e(e){return function(t,r){const{locale:o,...s}=r||{},c=[h({href:t,locale:o||n,domain:window.location.host})];Object.keys(s).length>0&&c.push(s),e(...c),a.default(l.localeCookie,u,n,o)}}return{...r,push:e(r.push),replace:e(r.replace),prefetch:e(r.prefetch)}}),[n,u,r])},getPathname:h}};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("../../routing/config.js"),n=require("./ClientLink.js"),i=require("./redirects.js"),u=require("./useBasePathname.js"),a=require("./useBaseRouter.js");function l(e){return e&&e.__esModule?e:{default:e}}var o=l(r);exports.default=function(l){const c=t.receiveLocalePrefixConfig(null==l?void 0:l.localePrefix),f=t.receiveLocaleCookie(null==l?void 0:l.localeCookie);function s(r,t){return o.default.createElement(n.default,e.extends({ref:t,localeCookie:f,localePrefix:c},r))}const d=r.forwardRef(s);return d.displayName="Link",{Link:d,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.clientRedirect({pathname:e,localePrefix:c},...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 i.clientPermanentRedirect({pathname:e,localePrefix:c},...t)},usePathname:function(){return u.default(c)},useRouter:function(){return a.default(c,f)}}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("../../routing/config.js"),n=require("./ClientLink.js"),l=require("./redirects.js"),i=require("./useBasePathname.js"),u=require("./useBaseRouter.js");function a(e){return e&&e.__esModule?e:{default:e}}var o=a(r);exports.default=function(a){const c=t.receiveLocalePrefixConfig(null==a?void 0:a.localePrefix),f=t.receiveLocaleCookie(null==a?void 0:a.localeCookie);function s(r,t){return o.default.createElement(n.default,e.extends({ref:t,localeCookie:f,localePrefix:c},r))}const d=r.forwardRef(s);return d.displayName="Link",{Link:d,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 l.clientRedirect({pathname:e,localePrefix:c},...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 l.clientPermanentRedirect({pathname:e,localePrefix:c},...t)},usePathname:function(){return i.default({localePrefix:c,defaultLocale:null==a?void 0:a.defaultLocale})},useRouter:function(){return u.default(c,f)}}};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/navigation"),r=require("react"),t=require("../../react-client/useLocale.js"),a=require("../../shared/utils.js");exports.default=function(u){const n=e.usePathname(),i=t.default();return r.useMemo((()=>{if(!n)return n;const e=a.getLocalePrefix(i,u);return a.hasPathnamePrefixed(e,n)?a.unprefixPathname(n,e):n}),[i,u,n])};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/navigation"),r=require("react"),a=require("../../react-client/useLocale.js"),t=require("../../shared/utils.js");exports.default=function(i){const l=e.usePathname(),n=a.default();return r.useMemo((()=>{if(!l)return l;let e=l;const r=t.getLocalePrefix(n,i.localePrefix);if(t.hasPathnamePrefixed(r,l))e=t.unprefixPathname(l,r);else if("as-needed"===i.localePrefix.mode&&i.defaultLocale===n&&i.localePrefix.prefixes){const r=t.getLocaleAsPrefix(n);t.hasPathnamePrefixed(r,l)&&(e=t.unprefixPathname(l,r))}return e}),[i.defaultLocale,i.localePrefix,n,l])};
@@ -1 +1 @@
1
- "use strict";function t(t){return function(t){return"object"==typeof t?null==t.host&&null==t.hostname:!/^[a-z]+:/i.test(t)}(t)&&!function(t){const e="object"==typeof t?t.pathname:t;return null!=e&&!e.startsWith("/")}(t)}function e(t,e){let r;return"string"==typeof t?r=n(e,t):(r={...t},t.pathname&&(r.pathname=n(e,t.pathname))),r}function n(t,e){let n=t;return/^\/(\?.*)?$/.test(e)&&(e=e.slice(1)),n+=e,n}function r(t,e){return e===t||e.startsWith("".concat(t,"/"))}function o(t){const e=function(){try{return"true"===process.env._next_intl_trailing_slash}catch(t){return!1}}();if("/"!==t){const n=t.endsWith("/");e&&!n?t+="/":!e&&n&&(t=t.slice(0,-1))}return t}function i(t){const e=t.replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp("^".concat(e,"$"))}function u(t){return t.includes("[[...")}function c(t){return t.includes("[...")}function s(t){return t.includes("[")}function a(t,e){const n=t.split("/"),r=e.split("/"),o=Math.max(n.length,r.length);for(let t=0;t<o;t++){const e=n[t],o=r[t];if(!e&&o)return-1;if(e&&!o)return 1;if(e||o){if(!s(e)&&s(o))return-1;if(s(e)&&!s(o))return 1;if(!c(e)&&c(o))return-1;if(c(e)&&!c(o))return 1;if(!u(e)&&u(o))return-1;if(u(e)&&!u(o))return 1}}return 0}Object.defineProperty(exports,"__esModule",{value:!0}),exports.getLocalePrefix=function(t,e){var n;return"never"!==e.mode&&(null===(n=e.prefixes)||void 0===n?void 0:n[t])||"/"+t},exports.getSortedPathnames=function(t){return t.sort(a)},exports.hasPathnamePrefixed=r,exports.isLocalizableHref=t,exports.localizeHref=function(n,o){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:o,u=arguments.length>3?arguments[3]:void 0,c=arguments.length>4?arguments[4]:void 0;if(!t(n))return n;const s=o!==i,a=r(c,u);return(s||a)&&null!=c?e(n,c):n},exports.matchesPathname=function(t,e){const n=o(t),r=o(e);return i(n).test(r)},exports.normalizeTrailingSlash=o,exports.prefixHref=e,exports.prefixPathname=n,exports.templateToRegex=i,exports.unprefixPathname=function(t,e){return t.replace(new RegExp("^".concat(e)),"")||"/"};
1
+ "use strict";function t(t){return function(t){return"object"==typeof t?null==t.host&&null==t.hostname:!/^[a-z]+:/i.test(t)}(t)&&!function(t){const e="object"==typeof t?t.pathname:t;return null!=e&&!e.startsWith("/")}(t)}function e(t,e){let r;return"string"==typeof t?r=n(e,t):(r={...t},t.pathname&&(r.pathname=n(e,t.pathname))),r}function n(t,e){let n=t;return/^\/(\?.*)?$/.test(e)&&(e=e.slice(1)),n+=e,n}function r(t,e){return e===t||e.startsWith("".concat(t,"/"))}function o(t){const e=function(){try{return"true"===process.env._next_intl_trailing_slash}catch(t){return!1}}();if("/"!==t){const n=t.endsWith("/");e&&!n?t+="/":!e&&n&&(t=t.slice(0,-1))}return t}function i(t){return"/"+t}function u(t){const e=t.replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp("^".concat(e,"$"))}function c(t){return t.includes("[[...")}function s(t){return t.includes("[...")}function a(t){return t.includes("[")}function f(t,e){const n=t.split("/"),r=e.split("/"),o=Math.max(n.length,r.length);for(let t=0;t<o;t++){const e=n[t],o=r[t];if(!e&&o)return-1;if(e&&!o)return 1;if(e||o){if(!a(e)&&a(o))return-1;if(a(e)&&!a(o))return 1;if(!s(e)&&s(o))return-1;if(s(e)&&!s(o))return 1;if(!c(e)&&c(o))return-1;if(c(e)&&!c(o))return 1}}return 0}Object.defineProperty(exports,"__esModule",{value:!0}),exports.getLocaleAsPrefix=i,exports.getLocalePrefix=function(t,e){var n;return"never"!==e.mode&&(null===(n=e.prefixes)||void 0===n?void 0:n[t])||i(t)},exports.getSortedPathnames=function(t){return t.sort(f)},exports.hasPathnamePrefixed=r,exports.isLocalizableHref=t,exports.localizeHref=function(n,o){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:o,u=arguments.length>3?arguments[3]:void 0,c=arguments.length>4?arguments[4]:void 0;if(!t(n))return n;const s=o!==i,a=r(c,u);return(s||a)&&null!=c?e(n,c):n},exports.matchesPathname=function(t,e){const n=o(t),r=o(e);return u(n).test(r)},exports.normalizeTrailingSlash=o,exports.prefixHref=e,exports.prefixPathname=n,exports.templateToRegex=u,exports.unprefixPathname=function(t,e){return t.replace(new RegExp("^".concat(e)),"")||"/"};
@@ -1,2 +1,5 @@
1
1
  import { LocalePrefixConfigVerbose, LocalePrefixMode, Locales } from '../../routing/types';
2
- export default function useBasePathname<AppLocales extends Locales, AppLocalePrefixMode extends LocalePrefixMode>(localePrefix: LocalePrefixConfigVerbose<AppLocales, AppLocalePrefixMode>): string | null;
2
+ export default function useBasePathname<AppLocales extends Locales, AppLocalePrefixMode extends LocalePrefixMode>(config: {
3
+ localePrefix: LocalePrefixConfigVerbose<AppLocales, AppLocalePrefixMode>;
4
+ defaultLocale?: AppLocales[number];
5
+ }): string | null;
@@ -18,6 +18,7 @@ template: string,
18
18
  /** E.g. `/users/23-jane` */
19
19
  pathname: string): boolean;
20
20
  export declare function getLocalePrefix<AppLocales extends Locales, AppLocalePrefixMode extends LocalePrefixMode>(locale: AppLocales[number], localePrefix: LocalePrefixConfigVerbose<AppLocales, AppLocalePrefixMode>): string;
21
+ export declare function getLocaleAsPrefix(locale: string): string;
21
22
  export declare function templateToRegex(template: string): RegExp;
22
23
  export declare function getSortedPathnames(pathnames: Array<string>): string[];
23
24
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "3.25.0",
3
+ "version": "3.25.2",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "funding": [
@@ -88,11 +88,11 @@
88
88
  "dependencies": {
89
89
  "@formatjs/intl-localematcher": "^0.5.4",
90
90
  "negotiator": "^1.0.0",
91
- "use-intl": "^3.25.0"
91
+ "use-intl": "^3.25.2"
92
92
  },
93
93
  "peerDependencies": {
94
94
  "next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0",
95
95
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || >=19.0.0-rc <19.0.0"
96
96
  },
97
- "gitHead": "4e3e9151d9b962ec36afcd19e420c49f5b316124"
97
+ "gitHead": "cdcff43e0a606bc9990623d819de9c37fea895a4"
98
98
  }