InetIntel / ioda-ui

Other
3 stars 0 forks source link

Fix page reload issue #145

Closed ydaniju closed 3 weeks ago

ydaniju commented 1 month ago

Description of the Problem

Previously, it was possible to listen to changes in the browser url using

this.props.history.listen((location, action) => {
  window.location.reload();
});

After migrating to v6 of react router DOM, history.listen was not usable since it had been removed. In replacement, the following approach was taken

  const handleLocationChange = () => {
    window.location.reload();
  };

  useEffect(() => {
    window.addEventListener("popstate", handleLocationChange);

    return () => {
      window.removeEventListener("popstate", handleLocationChange);
    };
  }, []);

The popstate event did not however capture the full scope of the kind of url changes that should trigger a page reload.

Fix

Use window.location.href to determine when to trigger a reload. This change ensures that any change in the url (path name, query params and hash) will cause a reload.

Closes https://github.com/InetIntel/ioda-ui/issues/146