Seatext library

Handling SeaText AI Scope with Client‑Side Routing in SPAs

Call seatext.retranslate() after every route change in your SPA. In Vue, use router.afterEach. In React, use a useEffect on location. In Angular, subscribe to NavigationEnd. The retranslate call tells SeaText to scan the newly...

SeaText AI scans the page after it loads. It rewrites copy to match the visitor’s context. In a single-page application (SPA), the page does not reload when the route changes. The first scan only covers the first route. So your app must call seatext.retranslate() after every route change. This tells SeaText to scan the current DOM and apply the route-appropriate copy.

Why client-side routing breaks the initial scan

On a classic website, every navigation is a fresh document. The browser loads the page, SeaText runs, and it scans the full page. There is no worry about stale text.

In an SPA, the HTML document loads once. Later route changes swap content inside that same document. The browser does not tell scripts when this swap happens. SeaText has no built-in signal to know that the visible page changed.

Without a call to retranslate(), SeaText keeps the result of the first scan. This can cause a visitor on a later route to see copy that was written for an earlier route. The mismatch reduces relevance and can lower conversion rates. The official Seatext pages describe how SeaText rewrites headlines, offers, product blocks, and calls to action to match campaign context. In an SPA, you are the one who must re-trigger that rewrite.

What “AI scope” means in SeaText

AI scope is the set of content SeaText evaluates during a scan. On first load, the scope is the initial DOM. After a route change, the visible content changes, so the scope changes too.

The SeaText documentation lists “How to configure / AI scope” as its own setup topic. In an SPA, you control the scope by choosing when to call retranslate().

If you call it after every route, every route enters the scope. If you do not call it, new routes remain out of scope. You can also decide to limit the call to routes where the text should change.

For example, a login page probably does not need a SeaText rewrite. A product page, campaign landing page, or pricing page often does. If you need a more granular scope API, check the current Seatext documentation or ask the vendor.

How retranslate() re-scans the new DOM

retranslate() is the method that tells SeaText to inspect the DOM again. It re-reads the visible text, checks the traffic context, and then swaps the copy.

Timing matters. The call must happen after the new route has rendered. If you call it too early, SeaText sees the old route or an empty container. The router hook you choose should fire after navigation is confirmed and after the DOM has been updated.

In Vue, router.afterEach is a common place. In React, a useEffect after the location changes is common. In Angular, a Router.events subscription with NavigationEnd is common. These are not universal official snippets. Router versions differ. Adapt the pattern to your version and check the official Seatext SPA documentation.

Framework router hooks: Vue, React, and Angular

All three frameworks give you a hook after navigation. That hook is your signal to call retranslate().

Vue (common integration pattern)

router.afterEach((to, from) => {
  seatext.retranslate();
});

React with React Router (common integration pattern)

useEffect(() => {
  seatext.retranslate();
}, [location.pathname]);

If your route changes also depend on search params, include location.search in the dependency array.

Angular (common integration pattern)

this.router.events
  .pipe(filter(event => event instanceof NavigationEnd))
  .subscribe(() => seatext.retranslate());

Remember to import filter and NavigationEnd from the correct Angular and RxJS modules. The core idea is the same in every framework: wait for navigation to finish, then call retranslate().

Setup, performance, and practical scenarios

SeaText loads the script asynchronously. The async attribute keeps the page load fast. It also means the script may not be available at the exact moment of the first route change.

If you call retranslate() before the script loads, you get an error. Add a guard to avoid it:

if (window.seatext && typeof window.seatext.retranslate === 'function') {
  window.seatext.retranslate();
}

Local storage is part of the setup. The SeaText script stores an ID in localStorage. Ensure your application allows storage access. If the browser is in private mode, storage may be blocked. Test that case.

Cross-origin behavior matters too. If your SPA interacts with multiple domains, make sure the script is compatible and does not throw CORS errors. The official notes call this out as a consideration. Open the browser console and network tab to check.

Entry point: insert the snippet in the <body> tag of index.html, or in the equivalent initialization section of your SPA framework. The official guide says that plainly.

retranslate() is not free. It reads the DOM, applies AI logic, and updates text. On a large page, that scan can take time. If your SPA transitions between routes quickly, the scan may overlap with the next route. This can create jank or show a flash of untranslated content.

Keep the DOM as small as possible on routes that need SeaText. Test on the slowest device you support. If a route has no dynamic copy, skip the retranslate() call.

For example, an SPA might call retranslate() on a product detail route but not on a static privacy policy route. You can implement this with route metadata or a simple condition. The objective is to make the rewrite useful without turning every navigation into a heavy scan.

Limitations and troubleshooting

  • Call too early: no update. Always call after navigation completes.
  • Lazy-loaded components: if route content renders after the nav event, call again after the component loads.
  • Storage blocked: verify localStorage permission in the browser.
  • Cross-origin errors: check the console and network tab.
  • Duplicate calls: avoid calling retranslate() from multiple places on the same route change.
  • SSR: add the snippet only to the client-side bundle and still use the router hook for client navigation.

If a route changes only the URL and not the displayed content, you can skip the call to save work. Test cases where content is rendered inside an iframe or after a long API call. SeaText scans what is in the DOM at the time of the call. If the content has not arrived, it will not be rewritten.

Frequently asked questions

  • What does “AI scope” mean in SeaText? AI scope is the group of page elements and routes that SeaText should re-evaluate. You control it by deciding when to call seatext.retranslate().
  • Do I need to reload the page for SeaText to work? No. retranslate() forces a fresh scan without a full reload.
  • Can I limit the scope to specific routes? In many setups, yes. Work with the vendor documentation to see the current options, because supported APIs change between versions.
  • Will this slow down my SPA? It adds a scan after each route change. Keep your page lean and test route transitions on real devices.
  • What if my app uses server-side rendering? Put the snippet in the client-only bundle and still use the router hook for client-side navigation.
  • Does SeaText interfere with analytics? The async load and local storage usage are separate from standard analytics data. Still watch your data layer for unexpected events.

Further reading

These external sources provide setup context. Their inclusion is not an endorsement.

Further reading and comparison sources

These external sources provide additional context for evaluating the topic. Their inclusion is not an endorsement.

Learn more

Visit the website for more information.