[WEB-5040] feat: admin react-router migration (#7922)

This commit is contained in:
Aaron 2025-11-06 00:09:35 -08:00 committed by GitHub
parent 545bfa203e
commit 315e1d5eb0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
105 changed files with 2452 additions and 798 deletions

View file

@ -0,0 +1,34 @@
"use client";
import { useMemo } from "react";
import { useLocation, useNavigate, useSearchParams as useSearchParamsRR } from "react-router";
import { ensureTrailingSlash } from "./helper";
export function useRouter() {
const navigate = useNavigate();
return useMemo(
() => ({
push: (to: string) => navigate(ensureTrailingSlash(to)),
replace: (to: string) => navigate(ensureTrailingSlash(to), { replace: true }),
back: () => navigate(-1),
forward: () => navigate(1),
refresh: () => {
location.reload();
},
prefetch: async (_to: string) => {
// no-op in this shim
},
}),
[navigate]
);
}
export function usePathname(): string {
const { pathname } = useLocation();
return pathname;
}
export function useSearchParams(): URLSearchParams {
const [searchParams] = useSearchParamsRR();
return searchParams;
}