Multi-page sites
On a multi-page site, each link loads a new page, and the widget starts fresh on every page:- Audio stops.
- An open text or voice conversation ends.
- The widget on the new page starts with an empty chat.
Browsers can’t keep a voice conversation connected across a full page load, so there’s no setting that changes this.
Single-page apps
In a single-page app, your router changes what’s on screen without loading a new page. The widget only changes content when you tell it to.Use one widget for the whole app
We recommend one widget instance for the life of the app:- Create the widget once, in part of your layout that stays on screen across routes, not in the area your router replaces.
- Pass a content identifier when you create it, for example
sourceId. - On each route change, set the same identifier to the new article’s value, for example
player.sourceId = 'article-456'.
- Any agent conversation carries on, including a voice conversation in progress, and the chat history stays.
- An open chat panel stays open. The main widget and the sticky widget each have their own panel, though: if your router scrolls the main widget back into view, the sticky widget slides away just as it does when a reader scrolls up, and the main widget’s panel stays closed until the reader opens it. The conversation is still there.
What the agent knows
The agent is given details of the loaded content, such as its title, when a conversation starts. A conversation that’s already open when the reader changes route continues with the previous content as its context. The agent gets the new content in the next conversation. For example, a new conversation starts after a voice conversation ends or when the reader switches between text and voice. A text conversation has no end button, so it keeps the previous content until it ends or the reader starts a voice conversation.Choose one identifier type
- Use the same identifier type every time. If more than one identifier is set, the widget loads them all as a playlist (see the note on identifiers). A widget created with
sourceIdshould only ever havesourceIdupdated. - Prefer
sourceIdorcontentId. They stay the same if an article’s URL changes. - If you identify content by URL, set
sourceUrlto the article’s canonical URL, notlocation.href, which can include query strings and fragments. - Always set an identifier, and don’t clear it. A widget with no identifier sets
sourceUrlto the full URL of the current page (window.location.href). That URL doesn’t follow later route changes, and it’s sent along with any identifier you set afterward. - Keep the same
projectId. Changing it replaces the agent, which ends the conversation.
Routes without BeyondWords content
If the identifier you set has no published content, or the request for it fails, the widget:- Hides itself and fires
NoContentAvailable. - Ends any conversation and clears the chat.
showAgentWithoutContent, the widget shows your agent on its own instead and fires AgentAvailableWithoutContent.
For routes that have no identifier of their own, such as your home page, you can:
- Leave the widget as it is. It keeps the last article, and any audio or conversation carries on. The examples below do this.
- Destroy it. Call
player.destroy(), then create a new widget on the next article route. This ends any conversation.
If the widget lives inside a route component
If you create the widget inside a component that your router mounts and unmounts, such as an article page, calldestroy() when the component unmounts:
Examples
Each example creates the widget on the first article route, then updatessourceId on later article routes. On other routes, it leaves the widget as it is.
- JavaScript
- Next.js (App Router)
- Vue Router
Call
onRouteChange from your router after each route change.Events
These widget events help when content changes:
The widget hides its own interface when there’s no content, but your container stays on the page, along with any heading or spacing around it. To hide it too: