mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-23 07:59:59 -04:00
26 lines
711 B
TypeScript
26 lines
711 B
TypeScript
import { useEffect } from 'react';
|
|
import { useNavigate } from 'react-router';
|
|
import { DeeplinkEvent } from '~/util/events';
|
|
|
|
export const useDeeplinkEventHandler = () => {
|
|
const navigate = useNavigate();
|
|
useEffect(() => {
|
|
const handler = (e: DeeplinkEvent) => {
|
|
e.preventDefault();
|
|
|
|
const url = e.detail.url;
|
|
if (!url) return;
|
|
// If the URL has search params, we need to navigate to the URL with the search params
|
|
const [path, search] = url.split('?');
|
|
if (search) {
|
|
navigate({ pathname: path, search });
|
|
} else {
|
|
navigate(url);
|
|
}
|
|
};
|
|
|
|
document.addEventListener('deeplink', handler);
|
|
return () => document.removeEventListener('deeplink', handler);
|
|
}, [navigate]);
|
|
};
|