The history.location field doesn't update with @forge/bridge history object

I followed the guide on routing with a Custom UI: https://developer.atlassian.com/platform/forge/add-routing-to-a-full-page-app/

The history.push() calls work as expected: the app navigates to the new page and the URL is updated.

However, the value of history.location doesn’t seem to update: it is always the value of the original URL entered in the browser, and doesn’t change following calls to history.push().

In my case I want to check the existing location before pushing new locations, as I want to carry over existing query parameters. To accomplish this, I have to manually listen for location changes:

  const [history, setHistory] = useState<History | null>(null);
  const [location, setLocation] = useState<Location | null>(null);

  useEffect(() => {
    view.createHistory().then((history) => {
      history.listen((location) => {
        setLocation(location);
        console.log("location changed:", location); // this updates as expected
        console.log("history.location:", history.location); // this never changes
      });
      setHistory(history);
      setLocation(history.location);
    });
  }, []);

Am I missing something, or is this a bug in the framework? (I’m using @forge/bridge v2.0.0, currently the latest.)

1 Like

Hey @jbrunton,

Thanks for picking up on this. This sounds like a bug in the framework. We’ll have a look and see if we can implement a fix.

2 Likes

Was this fixed by this recent announcement in the changelog? Is there a Jira ticket to match?

3 May 2022

FIXED Fix for @forge/bridge history.location not updating when the route changes

This fix updates the location field within the history object. This occurs when the route changes and it’s returned from view.createHistory() .

To install the latest version of Forge bridge, run npm install @forge/bridge@latest in your resource directory.