@page "/flows" @inject IBonboardingService BonboardingService Conditional & branching · Bonboarding

Conditional & branching

Not every user should see every step. Steps can be gated by a condition, tours can fork on an answer, and Back walks the path the user actually took rather than the order the steps were declared in.

Conditional steps

When gates a step: one whose condition is false is skipped in whichever direction the user is going, and left out of the progress count. Here the billing step appears only for an administrator, and the beta step only with the feature flag on - change either and run the tour again, and watch the "1 of n" change.

Conditions are asked again on every transition, so a step can be unlocked by something an earlier step did (the lifecycle page shows one). Keep them cheap and free of side effects: load anything they need in a hook and keep it in the session's State. Prefer When when the reason is about the user or the data, and MissingTarget = Skip when it is about the page.

Live
@if (_betaEnabled) {
Beta
Insights
}
@ConditionalExample

Whether the tour runs at all

When decides about one step; CanStart decides about the whole tour. This one is for members only: with Signed in as above set to Viewer, StartAsync refuses it with a BonboardingException (you asked for it explicitly) and StartOnceAsync quietly returns null. BonboardingStartOptions.Force bypasses the check - and, given to StartOnceAsync, a completion, a dismissal or a snooze as well.

Live
@if (_membersResult is not null) {
@_membersResult
}
@CanStartExample

Branching on an answer

Footer buttons carry an effect. Combined with BonboardingStepActionEffect.GoTo this is the whole of a branching tour: no state machine to write. ResolveNext decides in code where Next goes - here the designers' step jumps over the developers' one to where the paths rejoin; return null to fall through to the next step, or BonboardingTourDefinition.EndStepId to finish the tour.

Back follows the path the user actually took, not the order the steps were declared in: on the last step it returns to whichever branch you chose. The visit history is session.History, shown here as you go, and ResolvePrevious overrides where Back goes when you need something else.

Live
@if (_branchTaken is not null) { Branch taken: @_branchTaken } @if (_branchPath is not null) { History: @_branchPath }

The branches point at the product on the conditional tour's sample above.

@BranchExample

Validation before advancing

CanAdvance holds the user on the step until it is satisfied, and ValidationMessage says why - shown in the card with role="alert", so screen readers read it out the moment the user is told no. The guard can set a more precise message of its own through its context. Here the tour will not move on until the field has a name of at least three characters; the step is TargetOnly, so the field can be typed into while the card is up.

Live

The guard decides for every way forward - the Next button, the arrow keys, an AdvanceOn trigger and an application signal - and every held advance publishes an AdvanceBlocked event, which, counted per step, points at instructions people find hard to follow. To stop the tour with an error instead, throw from OnBeforeLeave.

@ValidationExample
@code { private string _role = "Viewer"; private bool _betaEnabled; private string _projectName = string.Empty; private string? _branchTaken; private string? _branchPath; private string? _membersResult; private bool _membersRefused; private bool IsAdministrator => _role == "Administrator"; // A