Showcase

Blazor Bootstrap Layout Setup - Blazor WebAssembly

Build the layout of a Blazor WebAssembly app with Blazor Bootstrap: replace the MainLayout.razor code, clear the template CSS, and adjust the sticky header stacking order when you need to.
API Documentation

Prerequisites #

Assuming you followed the getting started docs for the initial setup.
  1. Blazor WebAssembly Project: Follow the getting started steps for the initial setup.
  2. Blazor Server Project: Follow the getting started steps for the initial setup.

Steps #

1. Replace MainLayout.razor page code with the below code.
NOTE
Remove all the CSS content from the Shared/MainLayout.razor.css file.
@inherits LayoutComponentBase

<BlazorBootstrapLayout StickyHeader="true">
    <HeaderSection>
        <ThemeSwitcher Class="ps-3 ps-lg-2" />
    </HeaderSection>

    <SidebarSection>
        <Sidebar2 Href="/"
                  ImageSrc="https://demos.blazorbootstrap.com/images/logo/logo-white.svg"
                  Title="Blazor Bootstrap"
                  BadgeText="3.4.0"
                  DataProvider="Sidebar2DataProvider"
                  WidthUnit="Unit.Px" />
    </SidebarSection>

    <ContentSection>
        @Body
    </ContentSection>

    <FooterSection>
        Footer links...
    </FooterSection>
</BlazorBootstrapLayout>

@code {
    private IEnumerable<NavItem> navItems = default!;

    private async Task<Sidebar2DataProviderResult> Sidebar2DataProvider(Sidebar2DataProviderRequest request)
    {
        if (navItems is null)
            navItems = GetNavItems();

        return await Task.FromResult(request.ApplyTo(navItems));
    }

    private IEnumerable<NavItem> GetNavItems()
    {
        navItems = new List<NavItem>
        {
            new NavItem { Id = "1", Href = "/", IconName = IconName.HouseDoorFill, Text = "Home", Match=NavLinkMatch.All},
            new NavItem { Id = "2", Href = "/counter", IconName = IconName.PlusSquareFill, Text = "Counter"},
            new NavItem { Id = "3", Href = "/fetchdata", IconName = IconName.Table, Text = "Fetch Data"},
        };

        return navItems;
    }
}

Sticky header stacking order #

When StickyHeader="true" is used, the layout header defaults to Bootstrap's sticky-navigation stacking level. To change that level, set the following variable in a global stylesheet loaded after blazor.bootstrap.css:
:root {
    --bb-layout-sticky-header-z-index: 1030;
}

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.