Multi-page tour
Steps can declare the route they belong to. The engine navigates there, waits for the page to render, and only then shows the step. If you wander off mid-tour it holds its place instead of dragging you back, and picks up where it left off when you return.
A tour across two pages
The tour starts here, crosses to the settings page for two steps and comes back for the last one - the navigation is the engine's, not this page's. Things to try:
- Run it and press Next: on the third step the engine navigates to the settings page, waits for it to render, and only then looks for the step's target.
- While the tour is on a settings step, press the browser's Back button to come back here. The tour holds its place with nothing of it left on screen, so the whole site - the docs navigation included - is yours again, and it resumes the moment you return to the settings page.
-
Reload the page part way through, then run the tour again: it resumes at the step you were on, because progress
is stored after every step and
StartAsyncresumes by default. Finish it and it starts from the top. - Start it from the settings page instead: the engine navigates back here for the first step.
The same tour is listed on the guidance page's tour list, which offers to resume it once you have left it part way.
Giving a step a route
The tour itself is plain data, defined once in C# and started from either page. Give every step of a multi-page
tour an explicit Id: ids are what is stored, so they are what makes resuming across a reload work.
-
A route is matched against the base-relative path, ignoring case, leading and trailing slashes, the query string and
the fragment:
"/settings/","settings"and"settings?tab=keys"are one route. -
A trailing
*makes the route a constraint rather than a destination: the step waits until the user is somewhere under it, and the engine does not navigate, since there is no single address to go to. -
While a step waits for its route, the session is
WaitingwithWaitReason = Route, and nothing is drawn - no overlay, no card - so the page stays fully usable. There is no timeout: a session waiting on a route holds no observers and no timers, so waiting costs nothing. AutoNavigateToStepRoute = false, set globally, turns navigation off entirely, so routes are only ever constraints.
public static class WorkspaceTour
{
public const string Id = "workspace";
public static BonboardingTourDefinition Create() => new()
{
Id = Id,
Version = 1, // bump when an edit changes what a saved position means
Steps =
{
new BonboardingStepDefinition { Id = "overview", Route = "workspace", Target = BonboardingStepTarget.Anchor("metrics"), ... },
new BonboardingStepDefinition
{
Id = "api-keys",
Route = "workspace/settings", // navigate here first, then look for the target
Target = BonboardingStepTarget.Anchor("api-keys"),
Title = "API keys",
},
new BonboardingStepDefinition { Id = "back-home", Route = "workspace", ... }, // and back again
},
};
}
// Both pages:
<button @onclick="() => BonboardingService.StartAsync(WorkspaceTour.Create())">Run the multi-page tour</button>
// A constraint rather than a destination: wait until the user is somewhere under /workspace.
new BonboardingStepDefinition { Route = "workspace/*", ... }
// Routes as constraints only, everywhere:
builder.Services.AddBitBonboardingServices(options => options.AutoNavigateToStepRoute = false);