Spaces:
Configuration error
Configuration error
Download src/components/hooks/useNavigation.ts from SreejithSHR/umami: direct link, hf CLI and curl.
- Browser
- Download file 846 Bytes
-
https://huggingface.co/spaces/SreejithSHR/umami/resolve/main/src/components/hooks/useNavigation.ts
- Command line
-
hf download hf://spaces/SreejithSHR/umami/src/components/hooks/useNavigation.ts
-
curl -L -o useNavigation.ts https://huggingface.co/spaces/SreejithSHR/umami/resolve/main/src/components/hooks/useNavigation.ts
846 Bytes
| import { useMemo } from 'react'; | |
| import { usePathname, useRouter, useSearchParams } from 'next/navigation'; | |
| import { buildUrl, safeDecodeURIComponent } from 'next-basics'; | |
| export function useNavigation(): { | |
| pathname: string; | |
| query: { [key: string]: string }; | |
| router: any; | |
| renderUrl: (params: any, reset?: boolean) => string; | |
| } { | |
| const router = useRouter(); | |
| const pathname = usePathname(); | |
| const params = useSearchParams(); | |
| const query = useMemo(() => { | |
| const obj = {}; | |
| for (const [key, value] of params.entries()) { | |
| obj[key] = safeDecodeURIComponent(value); | |
| } | |
| return obj; | |
| }, [params]); | |
| function renderUrl(params: any, reset?: boolean) { | |
| return reset ? pathname : buildUrl(pathname, { ...query, ...params }); | |
| } | |
| return { pathname, query, router, renderUrl }; | |
| } | |
| export default useNavigation; | |