mirror of
https://github.com/umami-software/umami.git
synced 2026-02-12 00:27:11 +01:00
Renamed query hooks. Fixed conversion bugs.
This commit is contained in:
parent
adca3c36d0
commit
7886c3f393
110 changed files with 423 additions and 489 deletions
|
|
@ -2,15 +2,11 @@ import { useMemo } from 'react';
|
|||
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
||||
import { buildUrl } from '@/lib/url';
|
||||
|
||||
export function useNavigation(): {
|
||||
pathname: string;
|
||||
query: { [key: string]: string };
|
||||
router: any;
|
||||
renderUrl: (params: any, reset?: boolean) => string;
|
||||
} {
|
||||
export function useNavigation() {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const params = useSearchParams();
|
||||
const [, teamId] = pathname.match(/^\/teams\/([a-f0-9-]+)/) || [];
|
||||
|
||||
const query = useMemo(() => {
|
||||
const obj = {};
|
||||
|
|
@ -26,5 +22,9 @@ export function useNavigation(): {
|
|||
return reset ? pathname : buildUrl(pathname, { ...query, ...params });
|
||||
}
|
||||
|
||||
return { pathname, query, router, renderUrl };
|
||||
function renderTeamUrl(url: string) {
|
||||
return teamId ? `/teams/${teamId}${url}` : url;
|
||||
}
|
||||
|
||||
return { pathname, query, router, renderUrl, renderTeamUrl, teamId };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue