#How to Intercept/handle browser's back button in React-router?

1 messages · Page 1 of 1 (latest)

jaunty void
#

I found this example online but it seems outdated and not for React-Router 6+

const {history} = useRouter();
  useEffect(() => {
    return () => {
      // && history.location.pathname === "any specific path")
      if (history.action === "POP") {
        history.replace(history.location.pathname, /* the new state */);
      }
    };
  }, [history])
young kite