@deix/rossini-core 2.2.0 → 2.3.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"createI18nMiddleware.d.ts","sourceRoot":"","sources":["../../../src/utils/middleware/createI18nMiddleware.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,eAAO,MAAM,UAAU,iBAAiB,CAAC;AAqBzC,eAAO,MAAM,oBAAoB;aACS,MAAM,EAAE;mBAAiB,MAAM;gBAC7D,WAAW,0BAiCpB,CAAC"}
1
+ {"version":3,"file":"createI18nMiddleware.d.ts","sourceRoot":"","sources":["../../../src/utils/middleware/createI18nMiddleware.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,eAAO,MAAM,UAAU,iBAAiB,CAAC;AAqBzC,eAAO,MAAM,oBAAoB;aACS,MAAM,EAAE;mBAAiB,MAAM;gBAC7D,WAAW,0BAmCpB,CAAC"}
@@ -13,6 +13,7 @@ const getLocale = (request, locales, defaultLocale) => {
13
13
  };
14
14
  export const createI18nMiddleware = ({ locales, defaultLocale }) => (request) => {
15
15
  const pathname = request.nextUrl.pathname;
16
+ const searchParams = request.nextUrl.searchParams;
16
17
  // Check if there is any supported locale in the pathname
17
18
  const pathnameIsMissingLocale = locales.every((locale) => !pathname.startsWith(`/${locale}/`) && pathname !== `/${locale}`);
18
19
  // Redirect if there is no locale
@@ -27,7 +28,8 @@ export const createI18nMiddleware = ({ locales, defaultLocale }) => (request) =>
27
28
  const locale = locales.find((l) => l === requestedLocale) || defaultLocale;
28
29
  // e.g. incoming request is /products
29
30
  // The new URL is now /en/products
30
- const response = NextResponse.redirect(new URL(`/${locale}${pathname.startsWith('/') ? '' : '/'}${pathname}`, request.url));
31
+ const newUrl = new URL(`/${locale}${pathname.startsWith('/') ? '' : '/'}${pathname}?${searchParams.toString()}`, request.url);
32
+ const response = NextResponse.redirect(newUrl);
31
33
  response.cookies.set(cookieName, locale);
32
34
  return response;
33
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deix/rossini-core",
3
- "version": "2.2.0",
3
+ "version": "2.3.1",
4
4
  "main": "lib/index.js",
5
5
  "repository": {
6
6
  "type": "git",