mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-25 02:57:31 +00:00
refactor: apply default vs transform to xproj
refactor(spa-services): clean code refactor(node-services): clean code, extract classes nto separate files refactor(angular-services): prime cache cleanup
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
|
||||
@@ -7,26 +6,27 @@ namespace Microsoft.AspNetCore.SpaServices
|
||||
{
|
||||
internal class SpaRouteConstraint : IRouteConstraint
|
||||
{
|
||||
private readonly string clientRouteTokenName;
|
||||
private readonly string _clientRouteTokenName;
|
||||
|
||||
public SpaRouteConstraint(string clientRouteTokenName) {
|
||||
if (string.IsNullOrEmpty(clientRouteTokenName)) {
|
||||
throw new ArgumentException("Value cannot be null or empty", "clientRouteTokenName");
|
||||
public SpaRouteConstraint(string clientRouteTokenName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(clientRouteTokenName))
|
||||
{
|
||||
throw new ArgumentException("Value cannot be null or empty", nameof(clientRouteTokenName));
|
||||
}
|
||||
|
||||
this.clientRouteTokenName = clientRouteTokenName;
|
||||
_clientRouteTokenName = clientRouteTokenName;
|
||||
}
|
||||
|
||||
public bool Match(HttpContext httpContext, IRouter route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection)
|
||||
{
|
||||
var clientRouteValue = (values[this.clientRouteTokenName] as string) ?? string.Empty;
|
||||
return !HasDotInLastSegment(clientRouteValue);
|
||||
}
|
||||
public bool Match(
|
||||
HttpContext httpContext,
|
||||
IRouter route,
|
||||
string routeKey,
|
||||
RouteValueDictionary values,
|
||||
RouteDirection routeDirection)
|
||||
=> !HasDotInLastSegment(values[_clientRouteTokenName] as string ?? string.Empty);
|
||||
|
||||
private bool HasDotInLastSegment(string uri)
|
||||
{
|
||||
var lastSegmentStartPos = uri.LastIndexOf('/');
|
||||
return uri.IndexOf('.', lastSegmentStartPos + 1) >= 0;
|
||||
}
|
||||
=> uri.IndexOf('.', uri.LastIndexOf('/') + 1) >= 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user