Suiram1.BlazorRoutesGenerator
1.1.0
dotnet add package Suiram1.BlazorRoutesGenerator --version 1.1.0
NuGet\Install-Package Suiram1.BlazorRoutesGenerator -Version 1.1.0
<PackageReference Include="Suiram1.BlazorRoutesGenerator" Version="1.1.0" />
paket add Suiram1.BlazorRoutesGenerator --version 1.1.0
#r "nuget: Suiram1.BlazorRoutesGenerator, 1.1.0"
// Install Suiram1.BlazorRoutesGenerator as a Cake Addin #addin nuget:?package=Suiram1.BlazorRoutesGenerator&version=1.1.0 // Install Suiram1.BlazorRoutesGenerator as a Cake Tool #tool nuget:?package=Suiram1.BlazorRoutesGenerator&version=1.1.0
BlazorRoutesGenerator
This library provides a code generator that detects routable components in .cs or in .razor files and create har-coded routes based on them.
The code generator will be recognize @page-directive in .razor files and the [Route("/")]-attribute in .cs files.
For each route defined by one of the mentioned ways the generator will generate two method. The first one will generate an relative uri to the page and the second one is an extensions of NavigationManager that will navigate to this page. The extension has the same method name as the uri creator method but with the prefix NavigateTo.
Route parameters
The generated methods supports route parameters of every by ASP.NET Core supported route parameter. A recognized route parameters gets in both methods of his route a parameter were you can specify this parameter.
Query parameters
The generated methods supports query parameter as well. Query parameters of a page are recognized when a property has the [SupplyParameterFromQuery]-attribute.
The name of the query parameter can provided using the Name-property of the attribute. If this property isn't specified the name of the property will be used.
The type of the query parameter is determined by the type of the property. Complex query parameters won't get serialized and only the ToString get called.
Generated methods
Every method generated is inside of a static class that is by default inside of the applications root namespace and is called Routes. The name of the methods is determined by the class/file name. If two classes/files has the same names as little as possible from the namespace is used to clearly identify the page.
For example the page ../Pages/Index.razor has the method name Index. But when there are two pages ../Pages/SectionA/Index.razor and ../Pages/SectionB/Index.razor the method names of these pages are SectionAIndex and SectionBIndex. In .razor files is for that purpose also the @namespace-directive supported.
Configuration
Some behaviors of the generator can be configured using a .json file. Using a configuration file you can change the namespace and the class name of the class containing the routes. You can also change the name of the methods that are responsable for a routable component.
The file have to be named BlazorRoutesGenerator.config.json and have to be included in the .csproj file of the project. You have add the following part to the .csproj file:
<ItemGroup>
<AdditionalFiles Include="BlazorRoutesGenerator.config.json" />
</ItemGroup>
If multiple BlazorRoutesGenerator.config.json are specified every file will be ignored.
The BlazorRoutesGenerator.config.json have to has the following structure:
{
"namespace": "MyApplication",
"className": "Routes",
"namesOverwrites": {
"SampleApp.Components.Pages.Weather": "RenamedPage",
"SampleApp.Components.Pages.Something.Page": "AnotherRenamedPage"
}
}
If you don't want to change a settings you can remove the json property and the default value will be used. The default namespace is you applications root namespace and the default class name is Routes. An invalid configuration or doubled names for example if rename a page to PageA but another page is by default named PageA the configuration will be ignored.
Limitations
Query parameters are only in .cs files supported. Inside of .razor files they won't be detected. In case that you want to use .razor files for HTML + CS and query parameters you can define the page in partial classes (more about that here) and define the query parameters there.
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. |
.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
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.