Skip to content

Window

Redirect to another URL

Usage:

ts
sw.window.redirect({
    url: 'https://www.shopware.com,
    newTab: true
})

Parameters:

NameRequiredDefaultDescription
urltrueThe title of the notification
newTabfalsefalseThe message of the notification

Return value:

Returns a promise without data.

Push to another page

For redirecting to other pages in the admin.

Usage:

The usage matches the Vue Router push capabilities. Here are two examples how to use it for redirecting to your own modules:

ts
sw.window.routerPush({
    name: 'sw.extension.sdk.index',
    params: {
        id: 'the_id_of_the_module' // can be get with context.getModuleInformation
    }
})
ts
sw.window.routerPush({
    path: `/extension/${the_id_of_the_module}` // id can be get with context.getModuleInformation
})

Parameters:

NameRequiredDefaultDescription
namefalseundefinedThe name of the route
pathfalseundefinedThe path of the route
paramsfalseundefinedAdditional params for the new route
replacefalsefalseShould not change the browser history

Return value:

Returns a promise without data.

Reload page

Useful for development. You can trigger a page reload on file changes.

Usage:

ts
sw.window.reload()

Parameters:

No parameters required.

Return value:

Returns a promise without data.

Get an unique identifier for the window

Available since Shopware v6.7.1.0

When it comes to session handling it can be useful to have a unique identifier for your window.

Usage:

ts
sw.window.getId()

Parameters

No parameters required

Return value:

A string representing an unique identifier for the current window

Example

In this example we check if the sessionStorage contains data from a former window. This can happen if a user uses the Duplicate Tab feature of some browsers.

ts
const windowId = sw.window.getId();
const storedWindowId = globalThis.sessionStorage.getItem('window-id');

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