mirror of
https://github.com/umami-software/umami.git
synced 2026-02-06 05:37:20 +01:00
Refactored to use app folder.
This commit is contained in:
parent
40cfcd41e9
commit
9a52cdd2e1
258 changed files with 2025 additions and 2258 deletions
|
|
@ -1,30 +1,24 @@
|
|||
import { useMemo } from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
||||
import { buildUrl } from 'next-basics';
|
||||
|
||||
export function usePageQuery() {
|
||||
const router = useRouter();
|
||||
const { pathname, search } = location;
|
||||
const { asPath } = router;
|
||||
const pathname = usePathname();
|
||||
const params = useSearchParams();
|
||||
|
||||
const query = useMemo(() => {
|
||||
if (!search) {
|
||||
return {};
|
||||
const obj = {};
|
||||
|
||||
for (const [key, value] of params.entries()) {
|
||||
obj[key] = decodeURIComponent(value);
|
||||
}
|
||||
|
||||
const params = search.substring(1).split('&');
|
||||
|
||||
return params.reduce((obj, item) => {
|
||||
const [key, value] = item.split('=');
|
||||
|
||||
obj[key] = decodeURIComponent(value);
|
||||
|
||||
return obj;
|
||||
}, {});
|
||||
}, [search]);
|
||||
return obj;
|
||||
}, [params]);
|
||||
|
||||
function resolveUrl(params, reset) {
|
||||
return buildUrl(asPath.split('?')[0], { ...(reset ? {} : query), ...params });
|
||||
return buildUrl(pathname, { ...(reset ? {} : query) });
|
||||
}
|
||||
|
||||
return { pathname, query, resolveUrl, router };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue