Waylume SDK (npm) Quick Start
This guide shows the basic setup for a web app using the npm package @gitsbt/waylume-sdk. For a PHP application, see the Waylume SDK for PHP (Composer) Quick Start.
1. Install the package
npm install @gitsbt/waylume-sdk2. Create the SDK files
Create a waylume/ directory at your app root and keep your SDK files there.
Typical structure:
your-app/
app/
layout.tsx
page.tsx
waylume-setup.tsx
waylume/
index.ts
summary1.json
summary2.json
...Put each guide definition in
waylume/*.jsonRegister all guides from
waylume/index.tsMount the global setup once from
app/layout.tsxRender the launcher on the page where you want users to open guides
3. Add stable targets to your UI
Use data-waylume on elements that should be referenced by guidance steps.
4. Create a flow definition
i18n is optional. If it is omitted, the SDK uses the base label, summary, and instruction values as-is.
expectedUrlPattern must be a same-site path that starts with /, such as /login or /dashboard. Do not use absolute URLs such as https://example.com/login; the SDK rejects them to keep flows within the current site.
5. Register the flow
registerFlows() accepts an array. Each item in that array is one imported JSON flow file from waylume/.
6. Add a global setup component
Mount that component once near the root of your app, typically from app/layout.tsx.
7. Render a launcher
locale is optional. When provided, the launcher panel and flow text use the matching localized strings and fall back to the base fields if a translation is missing.
If your app already has a language state, route locale, or locale cookie, pass that current value to locale instead of hard-coding it.
The SDK does not read your app's i18n state automatically. Keep the locale prop in sync with your app if users can switch languages without a full page reload.
Common pitfalls
Mounting the launcher on every page
WaylumeGlobal should be mounted once from the root layout. The launcher only needs to be rendered on pages where you want users to open the guide panel.
Removing usePathname from WaylumeGlobal
In the Next.js App Router, the root layout is not remounted during client-side <Link> navigation. Keep usePathname and useEffect([pathname]) so scheduleAutoResume() can run after route changes.
Missing expectedUrlPattern on navigation steps
For flows that continue across pages, set expectedUrlPattern on the first step and on steps that wait for navigation. Use same-site paths only. Absolute URLs and protocol-relative URLs are not valid.
Mismatched target and data-waylume
The JSON target value must exactly match the UI element's data-waylume value.
Missing 'use client'
Add 'use client' to files that import the SDK client APIs or render the launcher, such as waylume/index.ts, app/waylume-setup.tsx, and launcher components.
Result
At that point, adding a new guide is mainly:
Add
data-waylumetargets to the UICreate a flow JSON file in
waylume/Register the new flow in
waylume/index.tsKeep
WaylumeGlobalmounted fromapp/layout.tsx
最終更新
役に立ちましたか?

