feat(routing): shorten language URL prefixes to ISO codes with legacy redirects
All checks were successful
Deploy to Frontend Servers / deploy (push) Successful in 31s

Rename the localized URL prefixes from full English names to short
ISO-style codes:
  /chinese    -> /cn
  /japanese   -> /ja
  /korean     -> /ko
  /vietnamese -> /vi
  /indonesian -> /id
  /malay      -> /ms

Add legacyLanguageRedirects mapping and a LegacyLangRedirect component
in App.tsx so links shared on WeChat (and elsewhere) that still use the
long-form paths keep landing on the right page. The redirect preserves
the sub-path, query string, and hash, e.g.
  /malay/browse?post=42#x -> /ms/browse?post=42#x

Also refresh doc-comment examples in i18n.tsx, FigmaBanner.tsx,
PublicLayout.tsx, and useLocalizedPath.ts so future readers see the new
prefixes.
This commit is contained in:
TerryM
2026-06-04 12:01:38 +08:00
parent 53614189ce
commit 1b52a6d93d
8 changed files with 122 additions and 32 deletions

View File

@@ -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";
@@ -19,7 +26,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";
@@ -94,6 +114,21 @@ 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()
) : (