@lovalingo/lovalingo 0.0.20 → 0.0.21
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/components/LangRouter.js +12 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
2
|
import { BrowserRouter, Routes, Route, Navigate, Outlet, useLocation, useParams, useNavigate } from 'react-router-dom';
|
|
3
|
+
function isNonLocalizedPath(pathname) {
|
|
4
|
+
if (pathname === '/robots.txt' || pathname === '/sitemap.xml')
|
|
5
|
+
return true;
|
|
6
|
+
if (pathname.startsWith('/.well-known/'))
|
|
7
|
+
return true;
|
|
8
|
+
return /\.(?:png|jpg|jpeg|gif|svg|webp|avif|ico|css|js|map|json|xml|txt|pdf|zip|gz|br|woff2?|ttf|eot)$/i.test(pathname);
|
|
9
|
+
}
|
|
3
10
|
/**
|
|
4
11
|
* NavigateExporter - Internal component that exports navigate function via ref
|
|
5
12
|
*/
|
|
@@ -28,8 +35,11 @@ function LangGuard({ defaultLang, langs }) {
|
|
|
28
35
|
// Valid language - render children (user's routes)
|
|
29
36
|
return React.createElement(Outlet, { context: { lang } });
|
|
30
37
|
}
|
|
31
|
-
function RedirectToDefaultLang({ defaultLang }) {
|
|
38
|
+
function RedirectToDefaultLang({ defaultLang, children }) {
|
|
32
39
|
const location = useLocation();
|
|
40
|
+
if (isNonLocalizedPath(location.pathname)) {
|
|
41
|
+
return React.createElement(React.Fragment, null, children);
|
|
42
|
+
}
|
|
33
43
|
const nextPath = location.pathname === '/' || location.pathname === ''
|
|
34
44
|
? `/${defaultLang}${location.search}${location.hash}`
|
|
35
45
|
: `/${defaultLang}${location.pathname}${location.search}${location.hash}`;
|
|
@@ -67,5 +77,5 @@ export function LangRouter({ children, defaultLang, langs, navigateRef }) {
|
|
|
67
77
|
React.createElement(Route, { path: ":lang/*", element: React.createElement(LangGuard, { defaultLang: defaultLang, langs: langs }) },
|
|
68
78
|
React.createElement(Route, { index: true, element: React.createElement(React.Fragment, null, children) }),
|
|
69
79
|
React.createElement(Route, { path: "*", element: React.createElement(React.Fragment, null, children) })),
|
|
70
|
-
React.createElement(Route, { path: "*", element: React.createElement(RedirectToDefaultLang, { defaultLang: defaultLang }) }))));
|
|
80
|
+
React.createElement(Route, { path: "*", element: React.createElement(RedirectToDefaultLang, { defaultLang: defaultLang }, children) }))));
|
|
71
81
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.0.
|
|
1
|
+
export declare const VERSION = "0.0.21";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.0.
|
|
1
|
+
export const VERSION = "0.0.21";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lovalingo/lovalingo",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"description": "React translation library with automatic routing, real-time AI translation, and zero-flash rendering. One-line language routing setup.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|