mirror of
https://github.com/kremalicious/umami.git
synced 2024-06-25 02:36:25 +02:00
28 lines
683 B
TypeScript
28 lines
683 B
TypeScript
import { useMemo } from 'react';
|
|
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
|
import { buildUrl } from 'next-basics';
|
|
|
|
export function useNavigation() {
|
|
const router = useRouter();
|
|
const pathname = usePathname();
|
|
const params = useSearchParams();
|
|
|
|
const query = useMemo(() => {
|
|
const obj = {};
|
|
|
|
for (const [key, value] of params.entries()) {
|
|
obj[key] = decodeURIComponent(value);
|
|
}
|
|
|
|
return obj;
|
|
}, [params]);
|
|
|
|
function makeUrl(params: any, reset?: boolean) {
|
|
return reset ? pathname : buildUrl(pathname, { ...query, ...params });
|
|
}
|
|
|
|
return { pathname, query, router, makeUrl };
|
|
}
|
|
|
|
export default useNavigation;
|