()
| 40 | } |
| 41 | |
| 42 | const useRoute = () => { |
| 43 | const [hash, setHash] = useState(window.location.hash); |
| 44 | useEffect(() => { |
| 45 | const onChange = () => setHash(window.location.hash); |
| 46 | window.addEventListener("hashchange", onChange); |
| 47 | return () => window.removeEventListener("hashchange", onChange); |
| 48 | }, []); |
| 49 | const parts = hash.replace(/^#\/?/, "").split("/").filter(Boolean); |
| 50 | return parts.length >= 2 ? { target: parts[0], slug: parts[1] } : null; |
| 51 | }; |
| 52 | |
| 53 | export const App = () => { |
| 54 | const route = useRoute(); |