1. Developer guides

Open a different page

Version: 0.4
Before you begin

You can programmatically navigate from the currently open page to a different one so the SitecoreAI user can immediately start working with it, with no manual action required. This is useful to perform in response to some other action. For example, when you create a new page from the Marketplace app using the Authoring and Management GraphQL API, and then decide to redirect the user to the new page.

To open a different page:

  1. In the SDK initialization code where you run the useMarketplaceClient hook, after the Effect Hook, create a new mutation function:

    const navigateToPage = () => {
      // Create a new page using the GraphQL API...
    
      // Navigate the user to the new page using the `itemId`:
      client?.mutate("pages.context", {
        params: {
          itemId: "<ID_OF_NEW_PAGE>",
        },
      });
    };

    Replace the placeholder with the ID of a page.

  2. In the return statement, create a button that runs the mutation function, then save your changes:

    <button onClick={navigateToPage}>Open another page</button>
  3. In the SitecoreAI Page builder, refresh the page, then open your Marketplace app.

  4. In the Marketplace app, click Open another page.

If you have suggestions for improving this article, let us know!