mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-24 18:47:30 +00:00
Create a new shared package, Microsoft.AspNet.SpaServices, to hold MapSpaFallbackRoute (and other common infrastructure yet to be added)
This commit is contained in:
32
Microsoft.AspNet.SpaServices/SpaRouteConstraint.cs
Normal file
32
Microsoft.AspNet.SpaServices/SpaRouteConstraint.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Routing;
|
||||
|
||||
namespace Microsoft.AspNet.SpaServices
|
||||
{
|
||||
internal class SpaRouteConstraint : IRouteConstraint
|
||||
{
|
||||
private readonly string clientRouteTokenName;
|
||||
|
||||
public SpaRouteConstraint(string clientRouteTokenName) {
|
||||
if (string.IsNullOrEmpty(clientRouteTokenName)) {
|
||||
throw new ArgumentException("Value cannot be null or empty", "clientRouteTokenName");
|
||||
}
|
||||
|
||||
this.clientRouteTokenName = clientRouteTokenName;
|
||||
}
|
||||
|
||||
public bool Match(HttpContext httpContext, IRouter route, string routeKey, IDictionary<string, object> values, RouteDirection routeDirection)
|
||||
{
|
||||
var clientRouteValue = (values[this.clientRouteTokenName] as string) ?? string.Empty;
|
||||
return !HasDotInLastSegment(clientRouteValue);
|
||||
}
|
||||
|
||||
private bool HasDotInLastSegment(string uri)
|
||||
{
|
||||
var lastSegmentStartPos = uri.LastIndexOf('/');
|
||||
return uri.IndexOf('.', lastSegmentStartPos + 1) >= 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user