New createHistory API in Forge bridge version 1.5.0

We’ve added a new view.createHistory API in Forge bridge version 1.5.0.

The createHistory API enables your custom UI app to manipulate the current page URL for routing within full page apps.

Run npm install @forge/bridge@latest in your resource directory to install the latest version of Forge bridge.

6 Likes

awesome :muscle: :tada:

1 Like

Nice addition !

1 Like

Hi @kchan,

I tested it with Custom UI and the react-router stuff, works awesome :slight_smile:

The only thing I really would like to do is support “Open link in new Tab”. Meaning: The a-href should contain the full URL with https://mysite.atlassian.net/...
BUT: Even though I manage to build the jira:projectPage base URI the opened URL is the CDN baseURL e.g. https://atlassian-cdn.foo123.atlassian.net/...

So the code snippet is not quite right, because it states this:

    <a
      href={to}  /// <---- DOES NOT WORK
      onClick={(event) => {
        event.preventDefault();
        history.push(to);
      }}

Question: Is there any way to get the site baseURL in a forge resolver?
I mean https://[SITE].atlassian.net/.

Because when using full baseURL in a-href a normal click would still route with onclick but a middle-mouse click would (for most users) open a new tab with the full URL correctly.

Is there a way to achieve this? :slight_smile:

thanks,
Bernhard

2 Likes

Hi @clouless,

Glad to hear the createHistory API works well!

Regarding your request to open full URLs, this is possible via the router.navigate and router.open functions from @forge/bridge. In particular, router.open will open a full URL in a new tab. See the documentation at https://developer.atlassian.com/platform/forge/runtime-reference/custom-ui-bridge/#open.

In the router.navigate and router.open APIs, a relative URL will be prefixed with the site URL, e.g. router.navigate('/browse') will navigate to https://[SITE].atlassian.net/browse

1 Like

Thanks for your fast answer :slight_smile: I know this works that way, but it is still a JS-only triggered thing. This does not solve the “Open link in new tab” problem, that would only work with the a-href and native browser support without JS.

Maybe you can elaborate if this can work in the future.

What would be great would be some method like “router.getBaseUrl()” which returns https://[SITE].atlassian.net :slight_smile:

UPDATE: :white_check_mark: Since the Custom UI is inside an iframe we can do it via document.location.ancestorOrigins

   <a
      href={`${document.location.ancestorOrigins[0]}${to}`}  /// <---- DOES WORK and prepends SITE.atlassian.net
      onClick={(event) => {
        event.preventDefault();
        history.push(to);
      }}
2 Likes