Blazouter 1.0.13

Prefix Reserved
dotnet add package Blazouter --version 1.0.13
                    
NuGet\Install-Package Blazouter -Version 1.0.13
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Blazouter" Version="1.0.13" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Blazouter" Version="1.0.13" />
                    
Directory.Packages.props
<PackageReference Include="Blazouter" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Blazouter --version 1.0.13
                    
#r "nuget: Blazouter, 1.0.13"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Blazouter@1.0.13
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Blazouter&version=1.0.13
                    
Install as a Cake Addin
#tool nuget:?package=Blazouter&version=1.0.13
                    
Install as a Cake Tool

Blazouter - Core Library

NuGet NuGet Downloads

A powerful React Router-like routing library for Blazor applications. This is the core library that provides the foundational routing capabilities for all Blazor hosting models.

Features

  • Type-safe - Full IntelliSense support
  • True nested routing - Full hierarchical route structures
  • Beautiful transitions - Smooth animations between routes
  • Programmatic navigation - Navigate imperatively with ease
  • Lazy loading - Load components on-demand for better performance
  • Built-in route guards - Protect routes with authentication/authorization
  • Dynamic route parameters - Easy access to route and query parameters
  • Flexible layout system - Default and per-route layouts with @Body support
  • Query string utilities - Type-safe query string builder and typed parameter parsing
  • TypeScript integration - Optional JavaScript interop for browser History and Document APIs

Installation

dotnet add package Blazouter

For hosting-specific implementations, also install:

  • Blazor Server: Blazouter.Server
  • Blazor Hybrid/MAUI: Blazouter.Hybrid
  • Blazor WebAssembly: Blazouter.WebAssembly

Quick Start

Blazor WebAssembly

// Program.cs
using Blazouter.Extensions;

builder.Services.AddBlazouter();

@using Blazouter.Models
@using Blazouter.Components

<Router Routes="@_routes" DefaultLayout="typeof(MainLayout)">
    <NotFound>
        <h1>404 - Page Not Found</h1>
    </NotFound>
</Router>

@code {
    private List<RouteConfig> _routes = new()
    {
        new RouteConfig
        {
            Path = "/",
            Component = typeof(Home),
            Transition = RouteTransition.Fade
        }
    };
}

Blazor Server

// Program.cs
using Blazouter.Extensions;
using Blazouter.Server.Extensions;

builder.Services.AddBlazouter();

app.MapRazorComponents<App>()
    .AddBlazouterSupport()
    .AddInteractiveServerRenderMode();

Blazor Hybrid (MAUI)

// MauiProgram.cs
using Blazouter.Hybrid.Extensions;

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder.UseMauiApp<App>();

        builder.Services.AddMauiBlazorWebView();
        
        // Add Blazouter support
        builder.AddBlazouterSupport();

        return builder.Build();
    }
}

@using Blazouter.Models
@using Blazouter.Components

<Router Routes="@_routes">
    <NotFound>
        <h1>404 - Page Not Found</h1>
    </NotFound>
</Router>

@code {
    private List<RouteConfig> _routes = new()
    {
        new RouteConfig
        {
            Path = "/",
            Component = typeof(Home),
            Transition = RouteTransition.Fade
        }
    };
}

Key Components

Router Component

The main router component that handles route matching and rendering.

RouterOutlet Component

Used in parent components to render child routes in nested routing scenarios.

Navigation links with automatic active state detection.

<RouterLink Href="/" Exact="true" ActiveClass="active">Home</RouterLink>
<RouterLink Href="/about" ActiveClass="active">About</RouterLink>

Layouts

Set a default layout for all routes and override per route:

<Router Routes="@_routes" DefaultLayout="typeof(MainLayout)">
    <NotFound><h1>404</h1></NotFound>
</Router>

@code {
    private List<RouteConfig> _routes = new()
    {
        // Uses DefaultLayout (MainLayout)
        new RouteConfig { Path = "/", Component = typeof(Home) },
        
        // Override with different layout
        new RouteConfig 
        { 
            Path = "/admin", 
            Component = typeof(Admin),
            Layout = typeof(AdminLayout)
        },
        
        // No layout for this route
        new RouteConfig 
        { 
            Path = "/print", 
            Component = typeof(Print),
            Layout = null
        }
    };
}

Route Configuration

new RouteConfig
{
    Path = "/users",
    Component = typeof(UserLayout),
    Title = "Users",
    Layout = typeof(MainLayout),  // Optional: override default layout
    Transition = RouteTransition.Slide,
    Guards = new List<Type> { typeof(AuthGuard) },
    Children = new List<RouteConfig>
    {
        new RouteConfig 
        { 
            Path = ":id", 
            Component = typeof(UserDetail) 
        }
    }
}

Route Guards

Create custom guards by implementing IRouteGuard:

using Blazouter.Models;
using Blazouter.Interfaces;

public class AuthGuard : IRouteGuard
{
    public async Task<bool> CanActivateAsync(RouteMatch match)
    {
        return await IsAuthenticated();
    }

    public Task<string?> GetRedirectPathAsync(RouteMatch match)
    {
        return Task.FromResult<string?>("/login");
    }
}

Lazy Loading

new RouteConfig
{
    Path = "/reports",
    ComponentLoader = async () =>
    {
        await Task.Delay(100); // Simulated delay
        return typeof(ReportsPage);
    }
}

Programmatic Navigation

@inject RouterNavigationService NavService

private void NavigateToUser()
{
    NavService.NavigateTo("/users/123");
}

Route Parameters

@inject RouterStateService RouterState

protected override void OnInitialized()
{
    var userId = RouterState.GetParam("id");
}

Query String Utilities

Type-safe query string manipulation with fluent API:

@using Blazouter.Utilities
@using Blazouter.Extensions
@inject RouterStateService RouterState
@inject RouterNavigationService NavService

// Typed query parameter parsing
protected override void OnInitialized()
{
    int page = RouterState.GetQueryInt("page", 1);
    bool active = RouterState.GetQueryBool("active", false);
    DateTime? date = RouterState.GetQueryDateTimeOrNull("date");
}

// Fluent query string building
private void SearchWithFilters()
{
    NavService.NavigateToWithQuery("/search", q => q
        .Add("term", "blazor")
        .Add("active", true)
        .Add("page", 2));
}

// Update query parameters
private void NextPage()
{
    NavService.NavigateToWithUpdatedQuery(RouterState, null, q => q
        .Set("page", currentPage + 1));
}

Supported types: string, int, long, decimal, double, bool, DateTime, Guid, enum, and nullable variants (15 type-safe methods each for Add() and Set()).

TypeScript Integration (Optional)

Enhanced browser integration with type-safe JavaScript interop using 5 specialized services:

// Enable JavaScript interop (optional)
builder.Services.AddBlazouterInterop();

Add to your index.html:

<script type="module" src="_content/Blazouter/js/index.js"></script>

Available Services:

  • ClipboardInterop: Clipboard operations (copy, read, permissions)
  • StorageInterop: localStorage & sessionStorage with JSON serialization
  • NavigationInterop: Browser History API (back/forward, URL info, hash, query params)
  • ViewportInterop: Viewport/device info (dimensions, device type, orientation, fullscreen)
  • DocumentInterop: Document manipulation (title, meta tags, scrolling, focus, CSS classes)
@using Blazouter.Interops

@inject StorageInterop Storage
@inject DocumentInterop Document
@inject ViewportInterop Viewport
@inject ClipboardInterop Clipboard
@inject NavigationInterop Navigation

// Navigation
await Navigation.GoBackAsync();
string url = await Navigation.GetCurrentUrlAsync();

// Document
await Document.SetTitleAsync("Home - My App");
await Document.ScrollToTopAsync();

// Storage
await Storage.SetLocalStorageAsync("key", myObject);
var data = await Storage.GetLocalStorageAsync<MyType>("key");

// Viewport
string device = await Viewport.GetDeviceTypeAsync();
bool isMobile = await Viewport.IsMobileAsync();

// Clipboard
await Clipboard.CopyTextAsync("text");

Transitions

Built-in transitions: None, Pop, Blur, Fade, Flip, Lift, Scale, Slide, Swipe, Reveal, Rotate, Curtain, SlideUp, SlideFade, Spotlight

new RouteConfig
{
    Path = "/",
    Component = typeof(Home),
    Transition = RouteTransition.Fade
}

Multi-Platform Support

  • Blazor Server
  • Blazor WebAssembly
  • Blazor Hybrid (MAUI)
  • .NET 6.0, 7.0, 8.0, 9.0, 10.0

Documentation

License

MIT License - see LICENSE for details.

Support

Made with ❤️ for the Blazor community

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Blazouter:

Package Downloads
Blazouter.WebAssembly

WebAssembly-specific extensions for Blazouter routing library. This package provides optimized components and integration for Blazor WebAssembly applications with client-side routing enhancements. Enables React Router-like routing features in Blazor WASM with full support for nested routes, route guards, lazy loading, smooth transitions, and programmatic navigation. Optimized for reduced bundle size and fast client-side performance.

Blazouter.Hybrid

Blazor Hybrid/MAUI-specific extensions for Blazouter routing library. This package provides optimized components and integration for Blazor Hybrid applications running on .NET MAUI. Enables React Router-like routing features in native mobile and desktop apps with full support for nested routes, route guards, lazy loading, smooth transitions, and programmatic navigation. Includes platform-specific optimizations for iOS, Android, macOS, and Windows.

Blazouter.Server

Server-side specific extensions for Blazouter routing library. This package provides the necessary components and integration for Blazor Server applications, including AddBlazouterSupport extension method. Enables React Router-like routing features in Blazor Server mode with full support for nested routes, route guards, lazy loading, smooth transitions, and programmatic navigation.

Blazouter.Web

Web App specific extensions for Blazouter routing library. This package provides the necessary components and integration for Blazor Web App applications (.NET 8+) that support both Server and WebAssembly render modes (Auto/Interactive). Enables React Router-like routing features in the unified Blazor Web App model with full support for nested routes, guards, lazy loading, and smooth transitions. Works seamlessly with InteractiveServer, InteractiveWebAssembly, and InteractiveAuto render modes.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.13 65 12/23/2025
1.0.12 400,527 11/25/2025
1.0.11 237 11/23/2025
1.0.10 455 11/19/2025
1.0.9 439 11/18/2025
1.0.8 274 11/16/2025
1.0.7 257 11/16/2025
1.0.6 265 11/16/2025
1.0.5 168 11/16/2025
1.0.2 173 11/15/2025
1.0.1 173 11/15/2025
1.0.0 182 11/15/2025