mirror of
https://github.com/makeplane/plane.git
synced 2025-12-15 19:37:51 +01:00
35 lines
895 B
TypeScript
35 lines
895 B
TypeScript
"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;
|
|
}
|