@forge/bridge
5.15.2-next.0-experimental-5b726e65.16.0-next.1
out/router/router.js~
out/router/router.jsModified+23
Index: package/out/router/router.js
===================================================================
--- package/out/router/router.js
+++ package/out/router/router.js
@@ -2,8 +2,14 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.router = void 0;
const bridge_1 = require("../bridge");
const callBridge = (0, bridge_1.getCallBridge)();
+/**
+ * Returns a URL object for a given location.
+ *
+ * @param location - The location to get the URL for
+ * @returns A URL object for the given location
+ */
const getUrl = async (location) => {
if (!(location === null || location === void 0 ? void 0 : location.target)) {
throw new Error('target is required for getUrl');
}
@@ -17,8 +23,14 @@
catch (error) {
throw new Error(`Failed to parse URL: ${url} (${error})`);
}
};
+/**
+ * Navigates to a location within the same tab.
+ *
+ * @param location URL or `NavigationLocation` object
+ * @returns a promise that resolves when navigation is complete
+ */
const navigate = (location) => {
if (typeof location === 'string') {
return callBridge('navigate', { url: location, type: 'same-tab' });
}
@@ -28,8 +40,14 @@
}
return callBridge('navigate', { ...location, type: 'same-tab' });
}
};
+/**
+ * Opens a new tab in the browser and navigates to the specified location.
+ *
+ * @param location URL or `NavigationLocation` object
+ * @returns a promise that resolves when navigation is complete
+ */
const open = (location) => {
if (typeof location === 'string') {
return callBridge('navigate', { url: location, type: 'new-tab' });
}
@@ -39,8 +57,13 @@
}
return callBridge('navigate', { ...location, type: 'new-tab' });
}
};
+/**
+ * Reloads the page.
+ *
+ * @returns a promise that resolves to void when the page is reloaded
+ */
const reload = async () => callBridge('reload');
exports.router = {
getUrl,
navigate,