Skip to content

Window ​

The Window API provides methods for navigation and window-related utilities inside the Shopware Administration.

ts
import { window as adminWindow } from "@shopware-ag/meteor-admin-sdk";

redirect() ​

Redirect to an external URL.

Usage ​

Use this method to open an external URL either in the current tab or a new tab.

ts
adminWindow.redirect({
  url: "https://www.shopware.com",
  newTab: true,
});

Parameters ​

NameRequiredDefaultDescription
urltrueThe URL to open
newTabfalsefalseOpen the URL in a new browser tab

Return value ​

Returns a promise without data.

routerPush() ​

Navigate to another page inside the Shopware Administration.

Usage ​

This method mirrors the behavior of Vue Router’s push().

Navigate using a named route:

ts
adminWindow.routerPush({
  name: "sw.extension.sdk.index",
  params: {
    id: "the_id_of_the_module", // can be retrieved with context.getModuleInformation
  },
});

Alternatively, navigate using a path:

ts
adminWindow.routerPush({
  path: `/extension/${the_id_of_the_module}`, // id can be retrieved with context.getModuleInformation
});

Parameters ​

NameRequiredDefaultDescription
namefalseundefinedName of the route
pathfalseundefinedPath of the route
paramsfalseundefinedAdditional params for the new route
replacefalsefalseReplace current browser history entry

Return value ​

Returns a promise without data.

reload() ​

Reload the current Administration page. This can be useful during development or when UI state must be reset.

Usage ​

ts
adminWindow.reload();

Parameters ​

No parameters required.

Return value ​

Returns a promise without data.

getId() ​

Available since Shopware v6.7.1.0

Returns a unique identifier for the current browser window. This is useful when working with session storage or detecting duplicated tabs.

Usage ​

ts
await adminWindow.getId();

Parameters ​

No parameters required.

Return value ​

A Promise<string> that resolves to a unique identifier for the current window.

Example ​

This example clears sessionStorage when a duplicated browser tab is detected. This can happen if a user uses the Duplicate Tab feature of some browsers.

ts
const windowId = await adminWindow.getId();
const storedWindowId = globalThis.sessionStorage.getItem("window-id");

if (windowId !== storedWindowId) {
  globalThis.sessionStorage.clear();
  globalThis.sessionStorage.setItem("window-id", windowId);
}

getPath() ​

Available since Shopware v6.7.3.0

Retrieve the current Administration router path.

Usage ​

ts
await adminWindow.getPath();

Parameters ​

No parameters required.

Return value ​

Returns a Promise<string> containing the full path, or an empty string if the router is not available.

Was this page helpful?
UnsatisfiedSatisfied
Be the first to vote!
0.0 / 5  (0 votes)