Class NanoRoutePrefixExtensions

Adds prefix-routing helpers that configure child route scopes under a shared base pattern.

Inheritance
object
NanoRoutePrefixExtensions
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
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 /* so child routes can be appended to it.

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 routeScopeBuilder, pattern, or configureRoutes is null.

ArgumentException

Thrown when pattern does not end with /*.

ArgumentException

Thrown when pattern has invalid route-template syntax.

InvalidOperationException

Thrown when pattern uses unsupported route-template features, references a missing value parser, or conflicts with an existing parser-backed branch.

In this article
Back to top Generated by DocFX