Asp.net Core 2 Razor Pages MapSpaFallback suggestion #346

Closed
opened 2025-08-09 17:15:56 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @pholly on 10/25/2017

MapSpaFallback works well for MVC routes but does not exist for the new Razor Pages.

If SpaRouteConstraint were public instead of internal with a little work developers can add the constraint to Razor pages:

//Starup.cs ConfigureServices
//thank you Scott Hanselman https://www.hanselman.com/blog/AddingACustomInlineRouteConstraintInASPNETCore10.aspx
services.Configure<RouteOptions>(options => 
                options.ConstraintMap.Add("spaRoute", typeof(SpaRouteConstraint)));
services.AddMvc()
                .AddRazorPagesOptions(options =>
                {
                    options.Conventions.AddPageRoute("/Index", "{*catchAll:spaRoute(catchAll)}");
                });

Would be even better if JavaScriptServices somehow added SpaRouteConstraint to the ConstraintMap.

For now I'll just copy the SpaRouteConstraint class.
Thanks,
Philip

*Originally created by @pholly on 10/25/2017* MapSpaFallback works well for MVC routes but does not exist for the new Razor Pages. If [SpaRouteConstraint](https://github.com/aspnet/JavaScriptServices/blob/2ba5a0ac930a055acc6e711a701ed43aa993ec8b/src/Microsoft.AspNetCore.SpaServices/Routing/SpaRouteConstraint.cs#L7) were `public` instead of `internal` with a little work developers can add the constraint to Razor pages: ```C# //Starup.cs ConfigureServices //thank you Scott Hanselman https://www.hanselman.com/blog/AddingACustomInlineRouteConstraintInASPNETCore10.aspx services.Configure<RouteOptions>(options => options.ConstraintMap.Add("spaRoute", typeof(SpaRouteConstraint))); services.AddMvc() .AddRazorPagesOptions(options => { options.Conventions.AddPageRoute("/Index", "{*catchAll:spaRoute(catchAll)}"); }); ``` Would be even better if `JavaScriptServices` somehow added `SpaRouteConstraint` to the `ConstraintMap`. For now I'll just copy the `SpaRouteConstraint` class. Thanks, Philip
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#346
No description provided.