// New hook to make links use the react-router `navigate` method instead of default browser behavior.

import { useNavigate } from 'react-router-dom'

export function useFixLinks() {
  // spread this return value on <a/> elements in order to make them navigate 
  const navigate = useNavigate();
  return { onClick: (e) => {
    if (e.target.tagName != "A") { return; }
    if (!e.target.href.includes(window.location.origin)) { return; }
    e.preventDefault();
    navigate(e.target.href.replace(window.location.origin, ""));
  }};
}