Merge branch 'main' into terry-wallet-login
Some checks failed
Deploy Staging (terry-wallet-login) / deploy (push) Failing after 30s
Some checks failed
Deploy Staging (terry-wallet-login) / deploy (push) Failing after 30s
# Conflicts: # src/App.tsx
This commit is contained in:
43
src/App.tsx
43
src/App.tsx
@@ -1,4 +1,11 @@
|
||||
import { BrowserRouter, Navigate, Route, Routes } from "react-router-dom";
|
||||
import {
|
||||
BrowserRouter,
|
||||
Navigate,
|
||||
Route,
|
||||
Routes,
|
||||
useLocation,
|
||||
useParams,
|
||||
} from "react-router-dom";
|
||||
import { I18nProvider } from "./i18n";
|
||||
import { MotionProvider } from "./motion";
|
||||
import { ToastProvider } from "./components/Toast";
|
||||
@@ -25,7 +32,20 @@ import { AdminRouteTree } from "./adminRouteTree";
|
||||
import { AdminRouterModeProvider } from "./adminRouterMode";
|
||||
import { ImageLightboxProvider } from "./components/messageStream/overlays/ImageLightbox";
|
||||
import { VideoPlayerProvider } from "./components/messageStream/overlays/VideoPlayer";
|
||||
import { localizedHomeRoutes } from "./languageRoutes";
|
||||
import { legacyLanguageRedirects, localizedHomeRoutes } from "./languageRoutes";
|
||||
|
||||
/**
|
||||
* Redirects shared links that still use the old long-form language prefix
|
||||
* (e.g. /chinese, /malay/browse) to the new short codes (/cn, /ms/browse).
|
||||
* Preserves the sub-path, query string, and hash.
|
||||
*/
|
||||
function LegacyLangRedirect({ to }: { to: string }) {
|
||||
const params = useParams();
|
||||
const { search, hash } = useLocation();
|
||||
const splat = params["*"];
|
||||
const sub = splat ? `/${splat}` : "";
|
||||
return <Navigate to={`${to}${sub}${search}${hash}`} replace />;
|
||||
}
|
||||
|
||||
const adminEnabled = import.meta.env.VITE_DISABLE_ADMIN !== "true";
|
||||
|
||||
@@ -117,6 +137,25 @@ export default function App() {
|
||||
))}
|
||||
</Route>
|
||||
|
||||
{/* Legacy long-form language URLs → short-code
|
||||
redirects. Shared links (e.g. WeChat) keep working. */}
|
||||
{legacyLanguageRedirects.map((redirect) => (
|
||||
<Route key={redirect.from}>
|
||||
<Route
|
||||
path={redirect.from}
|
||||
element={
|
||||
<LegacyLangRedirect to={redirect.to} />
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={`${redirect.from}/*`}
|
||||
element={
|
||||
<LegacyLangRedirect to={redirect.to} />
|
||||
}
|
||||
/>
|
||||
</Route>
|
||||
))}
|
||||
|
||||
{adminEnabled ? (
|
||||
AdminRouteTree()
|
||||
) : (
|
||||
|
||||
Reference in New Issue
Block a user