Hez2010.BlazorRouter 2.1.2

dotnet add package Hez2010.BlazorRouter --version 2.1.2
                    
NuGet\Install-Package Hez2010.BlazorRouter -Version 2.1.2
                    
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="Hez2010.BlazorRouter" Version="2.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hez2010.BlazorRouter" Version="2.1.2" />
                    
Directory.Packages.props
<PackageReference Include="Hez2010.BlazorRouter" />
                    
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 Hez2010.BlazorRouter --version 2.1.2
                    
#r "nuget: Hez2010.BlazorRouter, 2.1.2"
                    
#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 Hez2010.BlazorRouter@2.1.2
                    
#: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=Hez2010.BlazorRouter&version=2.1.2
                    
Install as a Cake Addin
#tool nuget:?package=Hez2010.BlazorRouter&version=2.1.2
                    
Install as a Cake Tool

BlazorRouter nuget

An awesome router for blazor inspired by react-router, providing declarative routing for Blazor.

Installation

Via nuget package:

dotnet add package Hez2010.BlazorRouter

Then append @using BlazorRouter to your _Imports.razor

Usage

Put <Switch> to the place where you want to route your contents.
Then use <Route> to config routing template with Template property.
In the end, you can put the routed content inside the <Route>.

Parameters in the routing template will be passed as IDictionary<string, object> with attribute [CascadingParameter(Name = "RouteParameters")].

The order of routing is from the top to the bottom in <Switch>, and it will use the first matched item.
If Template was not defined or defined as empty, it will match any path.

For example:

<Switch>
    <Route Template="/">
        <Home />
    </Route>
    <Route Template="/login">
        <Account Action="Login" />
    </Route>
    <Route Template="/register">
        <Account Action="Register" />
    </Route>
    <Route Template="/user/{id:string}">
        <User />
    </Route>
    <Route>
        <p>404</p>
    </Route>
</Switch>

Besides, you can nest Switch to use nested routing:

For example:

<Switch>
    <Route Template="/">
        <Home />
    </Route>
    <Route Template="/login">
        <Account Action="Login" />
    </Route>
    <Route Template="/register">
        <Account Action="Register" />
    </Route>
    <Route Template="/user/{id:string}/*">
        <Switch>
            <Route Template="/user/{id:string}/edit">
                <User Action="Edit" />
            </Route>
            <Route Template="/user/{id:string}/delete">
                <User Action="Delete" />
            </Route>
            <Route>
                <p>404 in /user/id</p>
            </Route>
        </Switch>
    </Route>
    <Route>
        <p>404</p>
    </Route>
</Switch>

* represents one (can be zero if it's the last segment in template) segment, and you can use ** to match multiple segments (>= 0).

Note: ** can only be the last segment.

<Switch>
    <Route Template="/">
        <Home />
    </Route>
    <Route Template="/login">
        <Account Action="Login" />
    </Route>
    <Route Template="/register">
        <Account Action="Register" />
    </Route>
    <Route Template="/user/*/edit">
        <User Action="Edit" />
    </Route>
    <Route Template="/user/*/delete">
        <User Action="Delete" />
    </Route>
    <Route>
        <p>404</p>
    </Route>
</Switch>

Live Example

Visit Sample
For source, please check out BlazorRouter.Sample.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed.  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 was computed.  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 was computed.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.2 102,708 3/14/2021
2.1.1 490 3/8/2021
2.1.0 511 3/8/2021
2.0.0 581 11/16/2020
1.3.0 646 5/19/2020
1.2.0 698 3/14/2020
1.1.1 678 11/26/2019
1.1.0 668 11/16/2019
1.0.2 466 8/16/2019
1.0.1 469 7/3/2019
1.0.0 469 6/28/2019

Fix states not being passed into routed contents