Showcase

Blazor Breadcrumb Service

Use Blazor Bootstrap breadcrumb service to update the breadcrumb from any page or component in your app. The examples below show how it works and how to set it up in a layout.
API Documentation
Use Blazor BreadcrumbService to update the breadcrumb from any page or component in your app.

How it works #

BreadcrumbService sends a new list of items to every Breadcrumb component on the page that has no Items set by its parent.
How to use:
  1. Add a Breadcrumb component without the Items parameter, usually in a layout.
  2. Inject BreadcrumbService in the page or component that knows the current location.
  3. Call Notify(...) with a List<BreadcrumbItem>. Set IsCurrentPage on the last item.
Use the buttons to send a different trail to the breadcrumb.
Razor
<Breadcrumb />

<div class="d-flex flex-wrap gap-2 mt-3">
    <Button Color="ButtonColor.Primary" @onclick="ShowOrders">Orders</Button>
    <Button Color="ButtonColor.Primary" @onclick="ShowOrder">Order 1001</Button>
    <Button Color="ButtonColor.Primary" @onclick="ShowSettings">Settings</Button>
</div>

@code {
    [Inject] BreadcrumbService BreadcrumbService { get; set; } = default!;

    protected override void OnAfterRender(bool firstRender)
    {
        // The Breadcrumb subscribes when it initializes, so send the first trail after the first render.
        if (firstRender)
            ShowOrders();
    }

    private void ShowOrders()
    {
        BreadcrumbService.Notify(new List<BreadcrumbItem>
        {
            new BreadcrumbItem { Text = "Home", Href = "/" },
            new BreadcrumbItem { Text = "Orders", IsCurrentPage = true }
        });
    }

    private void ShowOrder()
    {
        BreadcrumbService.Notify(new List<BreadcrumbItem>
        {
            new BreadcrumbItem { Text = "Home", Href = "/" },
            new BreadcrumbItem { Text = "Orders", Href = DemoRouteConstants.Demos_URL_BreadcrumbService },
            new BreadcrumbItem { Text = "Order 1001", IsCurrentPage = true }
        });
    }

    private void ShowSettings()
    {
        BreadcrumbService.Notify(new List<BreadcrumbItem>
        {
            new BreadcrumbItem { Text = "Home", Href = "/" },
            new BreadcrumbItem { Text = "Settings", IsCurrentPage = true }
        });
    }
}

How to setup #

1. Add the Breadcrumb component in MainLayout.razor page as shown below.
Razor
@inherits LayoutComponentBase

...

... MainLayout.razor code goes here ...

...

<Breadcrumb />

@Body
2. Inject BreadcrumbService, then call the Notify(...) method as shown below.
Razor
@code {
    [Inject] BreadcrumbService BreadcrumbService { get; set; } = default!;

    protected override void OnInitialized()
    {
        BreadcrumbService.Notify(new List<BreadcrumbItem>
        {
            new BreadcrumbItem { Text = "Home", Href = "/" },
            new BreadcrumbItem { Text = "Orders", IsCurrentPage = true }
        });

        base.OnInitialized();
    }
}

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please reload the page.