Skip to content

visit(): void

The visit method allows you to visit a given url. It is a wrapper around the Turbo.visit method.

Before performing the visit, a turbo:before-visit event is fired which you can listen to and perform some additional action.

Returned value

A returned value has a type of void because this method does not return anything.

Event Bus events

This API method dispatches the following events with the Event Bus:

Example

In this example we make a PageManagerApi call to advance to a given url.

    useStorefront(async (storefront) => {
        const pageManagerApi = storefront.getApiSync('PageManagerApi');

        pageManagerApi.visit('/some-url');
    });

Example

In this example we make a PageManagerApi call to restore a given url.

    useStorefront(async (storefront) => {
        const pageManagerApi = storefront.getApiSync('PageManagerApi');

        pageManagerApi.visit('/some-previous-url', 'restore');
    });

Example

In this example we make a PageManagerApi call to advance to a given url. On top of that we listen to the turbo:before-visit event and if the URL equals some-url we prevent the page from reloading.

    useStorefront(async (storefront) => {
        const pageManagerApi = storefront.getApiSync('PageManagerApi');

        pageManagerApi.visit('/some-url');

        document.addEventListener('turbo:before-visit', (event) => {
            if (event.detail.url === '/some-url') {
                event.preventDefault();
            }
        });
    });

Page Manager API methods reference