Class NanoRoutePrefixExtensions
Adds prefix-routing helpers that configure child route scopes under a shared base pattern.
Inherited Members
Namespace: NanoRoute
Assembly: NanoRoute.dll
Syntax
public static class NanoRoutePrefixExtensions
Remarks
Prefix scopes inherit the value parsers and metadata visible when the child scope is created. Later changes made inside the prefix scope stay local to that child branch.
Examples
builder.AddPrefix("/api/*", api => api
.AddHandler("GET", "/health/", (context, _) => Results.Ok()));
Methods
AddPrefix<TBuilder>(TBuilder, string, Action<RouteScopeBuilder>)
Creates a child route scope for the given prefix, invokes a configuration callback, and returns the current builder.
Declaration
public static TBuilder AddPrefix<TBuilder>(this TBuilder routeScopeBuilder, string pattern, Action<RouteScopeBuilder> configureRoutes) where TBuilder : notnull, RouteScopeBuilder
Parameters
| Type | Name | Description |
|---|---|---|
| TBuilder | routeScopeBuilder | |
| string | pattern | The base prefix. It must be a valid route pattern ending in |
| Action<RouteScopeBuilder> | configureRoutes | A callback that configures routes on the child route scope. |
Returns
| Type | Description |
|---|---|
| TBuilder | The current builder. |
Type Parameters
| Name | Description |
|---|---|
| TBuilder |
Examples
builder.AddPrefix("/api/*", api => api
.AddHandler("GET", "/health/", (context, _) => Results.Ok())
.AddHandler("GET", "/users/", (context, _) => Results.Ok()));
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
| ArgumentException | Thrown when |
| ArgumentException | Thrown when |
| InvalidOperationException | Thrown when |