mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-24 18:47:30 +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:
@@ -4,18 +4,34 @@ using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.AspNetCore.SpaServices;
|
||||
|
||||
// Putting in this namespace so it's always available whenever MapRoute is
|
||||
|
||||
namespace Microsoft.AspNetCore.Builder
|
||||
{
|
||||
public static class SpaRouteExtensions
|
||||
{
|
||||
private const string ClientRouteTokenName = "clientRoute";
|
||||
|
||||
public static void MapSpaFallbackRoute(this IRouteBuilder routeBuilder, string name, object defaults, object constraints = null, object dataTokens = null)
|
||||
{
|
||||
MapSpaFallbackRoute(routeBuilder, name, /* templatePrefix */ (string)null, defaults, constraints, dataTokens);
|
||||
}
|
||||
public static void MapSpaFallbackRoute(
|
||||
this IRouteBuilder routeBuilder,
|
||||
string name,
|
||||
object defaults,
|
||||
object constraints = null,
|
||||
object dataTokens = null)
|
||||
=> MapSpaFallbackRoute(
|
||||
routeBuilder,
|
||||
name,
|
||||
/* templatePrefix */ null,
|
||||
defaults,
|
||||
constraints,
|
||||
dataTokens);
|
||||
|
||||
public static void MapSpaFallbackRoute(this IRouteBuilder routeBuilder, string name, string templatePrefix, object defaults, object constraints = null, object dataTokens = null)
|
||||
public static void MapSpaFallbackRoute(
|
||||
this IRouteBuilder routeBuilder,
|
||||
string name,
|
||||
string templatePrefix,
|
||||
object defaults,
|
||||
object constraints = null,
|
||||
object dataTokens = null)
|
||||
{
|
||||
var template = CreateRouteTemplate(templatePrefix);
|
||||
|
||||
@@ -29,25 +45,27 @@ namespace Microsoft.AspNetCore.Builder
|
||||
{
|
||||
templatePrefix = templatePrefix ?? string.Empty;
|
||||
|
||||
if (templatePrefix.Contains("?")) {
|
||||
if (templatePrefix.Contains("?"))
|
||||
{
|
||||
// TODO: Consider supporting this. The {*clientRoute} part should be added immediately before the '?'
|
||||
throw new ArgumentException("SPA fallback route templates don't support querystrings");
|
||||
}
|
||||
|
||||
if (templatePrefix.Contains("#")) {
|
||||
throw new ArgumentException("SPA fallback route templates should not include # characters. The hash part of a URI does not get sent to the server.");
|
||||
if (templatePrefix.Contains("#"))
|
||||
{
|
||||
throw new ArgumentException(
|
||||
"SPA fallback route templates should not include # characters. The hash part of a URI does not get sent to the server.");
|
||||
}
|
||||
|
||||
if (templatePrefix != string.Empty && !templatePrefix.EndsWith("/")) {
|
||||
if (templatePrefix != string.Empty && !templatePrefix.EndsWith("/"))
|
||||
{
|
||||
templatePrefix += "/";
|
||||
}
|
||||
|
||||
return templatePrefix + $"{{*{ ClientRouteTokenName }}}";
|
||||
return templatePrefix + $"{{*{ClientRouteTokenName}}}";
|
||||
}
|
||||
|
||||
private static IDictionary<string, object> ObjectToDictionary(object value)
|
||||
{
|
||||
return value as IDictionary<string, object> ?? new RouteValueDictionary(value);
|
||||
}
|
||||
=> value as IDictionary<string, object> ?? new RouteValueDictionary(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user