BlazorPathHelper.Core
0.1.1
See the version list below for details.
dotnet add package BlazorPathHelper.Core --version 0.1.1
NuGet\Install-Package BlazorPathHelper.Core -Version 0.1.1
<PackageReference Include="BlazorPathHelper.Core" Version="0.1.1" />
<PackageVersion Include="BlazorPathHelper.Core" Version="0.1.1" />
<PackageReference Include="BlazorPathHelper.Core" />
paket add BlazorPathHelper.Core --version 0.1.1
#r "nuget: BlazorPathHelper.Core, 0.1.1"
#:package BlazorPathHelper.Core@0.1.1
#addin nuget:?package=BlazorPathHelper.Core&version=0.1.1
#tool nuget:?package=BlazorPathHelper.Core&version=0.1.1
BlazorPathHelper
BlazorPathHelper is a library that assists in managing URL paths within Blazor projects.
Main Features
- Automatically generates URL builders and menu item lists from path definitions
- Supports menu generation for various frameworks with simple implementation
Getting Started
Installation
Install BlazorPathHelper in your Blazor project.
dotnet add package BlazorPathHelper
Preparation
Create a WebPaths.cs file.
using BlazorPathHelper;
[BlazorPath]
public partial class WebPaths
{
[BlazorPathItem("Home")]
public const string Index = "/";
[BlazorPathItem("Sample1")]
public const string Sample = "/sample";
[BlazorPathItem("Sample1-a")]
public const string SampleChild = "/sample/child";
[BlazorPathItem("Sample2")]
public const string Counter = "/counter";
public const string CounterWithState = "/counter/{count:int}";
}
This will automatically generate the following class definition.
// <auto-generated />
// Appended to the original class
public partial class WebPaths
{
// Helper functions useful for building URLs
public partial class Helper
{
public static string Index() => "/";
public static string Sample() => "/sample";
public static string SampleChild() => "/sample/child";
public static string Counter() => "/counter";
public static string CounterWithState(int count) => string.Format("/counter/{0}", count);
}
// An array useful for dynamically creating menu items
public static readonly BlazorMenuItem[] MenuItem = [
new BlazorPathMenuItem(){
Name = "Home", // Menu name. Defaults to the variable name
Path = "/", // Page path
Children = [] // Submenus
// Other properties automatically generated to assist in menu creation
},
new BlazorPathMenuItem(){
Name = "Sample1",
Path = "/sample",
// Parses the URL and intelligently generates submenus
Children = [
new BlazorPathMenuItem(){
Name = "Sample1-a",
Path = "/sample/child",
Children = []
}
]
},
new BlazorPathMenuItem(){
Name = "Sample2",
Path = "/counter",
// Pages with parameters are not displayed in the menu
Children = []
}
];
}
Finally, change the definition on the razor page from @page to @attribute + Route.
@* @page "/counter/{count:int}" *@
@attribute [Route(WebPaths.CounterWithState)]
Usage
URL Builder
// Generate URL
var url = WebPaths.Helper.CounterWithState(1); // -> "/counter/1"
// Navigate to page
// @inject NavigationManager Nav
Nav.NavigateTo(url);
// With query
Nav.NavigateTo(
Nav.GetUriWithQueryParameter(url, "q", "test"), // -> "/counter/1?q=test"
forceLoad: true
);
Menu Generation
Create NavMenu.razor and NavMenuItem.razor.
@* NavMenu.razor *@
<nav>
@foreach (var menuItem in WebPaths.MenuItem)
{
<NavMenuItem MenuItem="menuItem"/>
}
</nav>
@* NavMenuItem.razor *@
@using BlazorPathHelper
@* A component that recursively displays menu items *@
@* The key attribute can use MenuItem.Index *@
<div @key="@MenuItem.Index">
<NavLink href="@MenuItem.Path" Match="@NavLinkMatch.All">
<span class="@MenuItem.Icon" aria-hidden="true"></span>
@MenuItem.Name
</NavLink>
@* Submenus *@
@foreach(var childMenuItem in MenuItem.Children)
{
<NavMenuItem MenuItem="childMenuItem"/>
}
</div>
@code {
[Parameter, EditorRequired]
public BlazorPathMenuItem MenuItem { get; set; } = default!;
}
Menu Customization
You can customize menu display using the BlazorPathItem attribute.
[BlazorPath]
public partial class WebPaths
{
// To hide from the menu, specify Visible = false
[BlazorPathItem(Visible = false)]
public const string Index = "/";
// Specify page name and icon (CSS class)
[BlazorPathItem("SampleA", Icon = "fas fa-cog")]
public const string Sample = "/sample";
[BlazorPathItem("SampleA-1", Icon = "fas fa-star")]
public const string SampleChild = "/sample/child";
// To add a description, specify it as the second argument
[BlazorPathItem("SampleA-2", "Description of the A-2 page")]
public const string SampleWithDesc = "/sample/child2";
// To recognize as a child element without URL connection, specify Group
[BlazorPathItem("SampleA-3", Group = Sample)]
public const string SampleChild3 = "/sample-3";
// To display a deeply nested hierarchy that is not connected to anything as a top-level menu, specify Group = "/"
[BlazorPathItem("SampleB", Group = Index)]
public const string SuperInnerItem = "/hoge/fuga/piyo";
// If specified as above, child pages will also be displayed in the menu
[BlazorPathItem("SampleB-1")]
public const string SuperInnerItemChild = "/hoge/fuga/piyo/child";
// For multilingual support, use nameof to specify resource keys and use IStringLocalizer in components
[BlazorPathItem(nameof(Resources.SampleTitle))]
public const string SampleLocalize = "/sample-l10n";
[BlazorPathItem(nameof(Resources.SampleTitle), nameof(Resources.SampleDesc))]
public const string SampleLocalizeWithDesc = "/sample-l10n-plus";
}
Implementation Examples for Each Framework
Blazor Template
Since the standard template does not include icons, add the following to index.html.
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
</head>
Then, use it as follows.
// WebPaths.cs
[BlazorPath]
public partial class WebPaths
{
[BlazorPathItem(Name="Home", Icon="bi-house-door-fill")]
public const string Home = "/";
[BlazorPathItem(Name="Sample1", Icon="bi-1-circle-fill")]
public const string Sample1 = "/sample1";
[BlazorPathItem(Name="Sample2", Icon="bi-2-circle-fill")]
public const string Sample2 = "/sample2";
[BlazorPathItem(Name="Sample3", Icon="bi-3-circle-fill")]
public const string Sample3 = "/sample3";
}
@* NavMenuItem.razor *@
@using BlazorPathHelper
<div class="nav-item ps-3 py-1" @key="@MenuItem.Index">
<NavLink class="nav-link" href="@MenuItem.Path"
Match="@(MenuItem.Path != "/" ? NavLinkMatch.Prefix : NavLinkMatch.All)">
<span class="me-2 fs-5 @MenuItem.Icon" aria-hidden="true"></span>
@MenuItem.Name
</NavLink>
@foreach(var childMenuItem in MenuItem.Children)
{
<nav class="flex-column">
<NavMenuItem MenuItem="childMenuItem"/>
</nav>
}
</div>
@code {
[Parameter, EditorRequired]
public BlazorPathMenuItem MenuItem { get; set; } = default!;
}
Implementation examples are available in Example.Plain.
FluentUI
Since FluentUI's Icon cannot be specified as is, extract the name part and specify it.
using BlazorPathHelper;
// To shorten, use using static
using static Microsoft.FluentUI.AspNetCore.Components.Icons.Regular.Size20;
[BlazorPath]
public partial class WebPaths
{
// Specify the icon with BlazorPathItem<T>
// ---------------------------------
[BlazorPathItem<Home>("Home")]
public const string Home = "/";
[BlazorPathItem<TextHeader1>("Sample1")]
public const string Sample1 = "/sample1";
[BlazorPathItem<TextHeader2>("Sample2")]
public const string Sample2 = "/sample2";
[BlazorPathItem<TextHeader3>("Sample3")]
public const string Sample3 = "/sample3";
}
Then, use it as follows.
@* NavMenuItem.razor *@
@using BlazorPathHelper
@if(MenuItem.Children.Length > 0)
{
<FluentNavGroup Href="@MenuItem.Path" Title="@MenuItem.Name" Icon="@((Icon)MenuItem.Icon)">
@foreach(var childMenuItem in MenuItem.Children)
{
<NavMenuItem MenuItem="childMenuItem"/>
}
</FluentNavGroup>
}
else
{
<FluentNavLink Href="@MenuItem.Path" Icon="@((Icon)MenuItem.Icon)" IconColor="Color.Accent">
@MenuItem.Name
</FluentNavLink>
}
@code {
[Parameter, EditorRequired]
public BlazorPathMenuItem MenuItem { get; set; } = default!;
}
Implementation examples are available in Example.FluentUI.
AntBlazor
The standard template (Pro) includes a feature to generate menus from objects, but the generation of these definitions can be simplified.
// Layout/BasicLayout.razor.cs
protected override async Task OnInitializedAsync()
{
_menuData = ConverterMenuDataItem(WebPaths.MenuItem);
}
private MenuDataItem[] ConverterMenuDataItem(BlazorPathMenuItem[] items)
{
return items.Select(item => new MenuDataItem {
Path = item.Path,
Name = item.Name,
Key = item.Index.ToString(),
Icon = item.Icon.ToString(),
Children = item.Children.Length > 0
? ConverterMenuDataItem(item.Children) : null
}).ToArray();
}
Then, it's the same as others.
// WebPaths.cs
using BlazorPathHelper;
[BlazorPath]
public partial class WebPaths
{
[BlazorPathItem("Home", Icon = "home")]
public const string Home = "/";
[BlazorPathItem("Sample1", Icon = "folder")]
public const string Sample1 = "/sample1";
[BlazorPathItem("Sample2", Icon = "folder")]
public const string Sample2 = "/sample2";
[BlazorPathItem("Sample3", Icon = "file")]
public const string Sample3 = "/sample3";
}
Implementation examples are available in Example.AntBlazor.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on BlazorPathHelper.Core:
| Package | Downloads |
|---|---|
|
BlazorPathHelper
BlazorPathHelper is a library that assists in managing URL paths within Blazor projects. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.6.0 | 404 | 6/24/2025 |
| 0.5.1 | 540 | 4/15/2025 |
| 0.5.0-alpha.29 | 169 | 4/15/2025 |
| 0.5.0-alpha.11 | 180 | 4/15/2025 |
| 0.5.0-alpha.8 | 166 | 4/13/2025 |
| 0.4.2 | 198 | 4/11/2025 |
| 0.4.1 | 262 | 4/10/2025 |
| 0.4.0-alpha.14 | 146 | 4/10/2025 |
| 0.4.0-alpha.13 | 154 | 4/9/2025 |
| 0.4.0-alpha.11 | 68 | 1/19/2025 |
| 0.4.0-alpha.7 | 107 | 1/4/2025 |
| 0.4.0-alpha.5 | 103 | 1/3/2025 |
| 0.3.4 | 219 | 1/3/2025 |
| 0.3.2 | 209 | 1/3/2025 |
| 0.3.1 | 196 | 1/3/2025 |
| 0.3.0-alpha.40 | 97 | 1/3/2025 |
| 0.3.0-alpha.37 | 91 | 1/3/2025 |
| 0.3.0-alpha.36 | 98 | 1/3/2025 |
| 0.3.0-alpha.31 | 103 | 1/3/2025 |
| 0.3.0-alpha.19 | 74 | 12/30/2024 |
| 0.3.0-alpha.17 | 74 | 12/29/2024 |
| 0.3.0-alpha.16 | 68 | 12/28/2024 |
| 0.3.0-alpha.15 | 72 | 12/28/2024 |
| 0.3.0-alpha.14 | 74 | 12/27/2024 |
| 0.3.0-alpha.13 | 73 | 12/27/2024 |
| 0.3.0-alpha.12 | 73 | 12/27/2024 |
| 0.3.0-alpha.11 | 72 | 12/26/2024 |
| 0.3.0-alpha.10 | 78 | 12/20/2024 |
| 0.3.0-alpha.8 | 92 | 12/16/2024 |
| 0.3.0-alpha.5 | 84 | 12/15/2024 |
| 0.2.11 | 192 | 12/29/2024 |
| 0.2.10 | 189 | 12/28/2024 |
| 0.2.8 | 203 | 12/16/2024 |
| 0.2.2 | 186 | 12/15/2024 |
| 0.2.0-alpha.24 | 84 | 12/15/2024 |
| 0.2.0-alpha.23 | 81 | 12/15/2024 |
| 0.2.0-alpha.21 | 72 | 12/15/2024 |
| 0.2.0-alpha.17 | 82 | 12/14/2024 |
| 0.2.0-alpha.14 | 73 | 12/14/2024 |
| 0.2.0-alpha.13 | 82 | 12/14/2024 |
| 0.2.0-alpha.11 | 87 | 12/12/2024 |
| 0.2.0-alpha.10 | 71 | 12/12/2024 |
| 0.2.0-alpha.7 | 73 | 12/11/2024 |
| 0.2.0-alpha.6 | 72 | 12/11/2024 |
| 0.2.0-alpha.5 | 72 | 12/11/2024 |
| 0.1.1 | 190 | 12/1/2024 |
| 0.1.0-alpha.17 | 76 | 12/1/2024 |
| 0.1.0-alpha.16 | 75 | 12/1/2024 |
| 0.1.0-alpha.13 | 73 | 12/1/2024 |
| 0.1.0-alpha.12 | 77 | 11/30/2024 |
| 0.1.0-alpha.8 | 80 | 11/30/2024 |
| 0.1.0-alpha.7 | 75 | 11/29/2024 |
| 0.1.0-alpha.6 | 72 | 11/29/2024 |