File size: 990 Bytes
0b9dc2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Shim for `next/navigation` so libraries written for Next.js (e.g. `onborda`)
// can run inside this Vite + react-router-dom app. Onborda only calls
// `router.push(route)` when a step has `nextRoute`/`prevRoute` set; we don't use
// those, so this no-op router is sufficient. If we ever need real navigation
// from inside a tour step, swap this for a wrapper that uses `react-router`.
export const useRouter = () => ({
	push: async (path: string) => {
		window.history.pushState({}, '', path);
		window.dispatchEvent(new PopStateEvent('popstate'));
	},
	replace: async (path: string) => {
		window.history.replaceState({}, '', path);
		window.dispatchEvent(new PopStateEvent('popstate'));
	},
	back: () => window.history.back(),
	forward: () => window.history.forward(),
	refresh: () => {},
	prefetch: async () => {},
});

export const usePathname = () => window.location.pathname;
export const useSearchParams = () => new URLSearchParams(window.location.search);