|
3 | 3 | using Microsoft.AspNet.Authorization; |
4 | 4 | using Microsoft.AspNet.Builder; |
5 | 5 | using Microsoft.AspNet.Hosting; |
6 | | -using Microsoft.AspNet.Http; |
7 | 6 | using Microsoft.AspNet.Identity.EntityFramework; |
8 | | -using Microsoft.AspNet.Routing; |
9 | 7 | using Microsoft.Data.Entity; |
10 | 8 | using Microsoft.Extensions.Configuration; |
11 | 9 | using Microsoft.Extensions.DependencyInjection; |
@@ -125,61 +123,4 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF |
125 | 123 | }); |
126 | 124 | } |
127 | 125 | } |
128 | | - internal static class SpaRouteExtensions { |
129 | | - private const string ClientRouteTokenName = "clientRoute"; |
130 | | - |
131 | | - public static void MapSpaFallbackRoute(this IRouteBuilder routeBuilder, string name, object defaults, object constraints = null, object dataTokens = null) { |
132 | | - MapSpaFallbackRoute(routeBuilder, name, /* templatePrefix */ (string)null, defaults, constraints, dataTokens); |
133 | | - } |
134 | | - |
135 | | - public static void MapSpaFallbackRoute(this IRouteBuilder routeBuilder, string name, string templatePrefix, object defaults, object constraints = null, object dataTokens = null) |
136 | | - { |
137 | | - var template = CreateRouteTemplate(templatePrefix); |
138 | | - |
139 | | - var constraintsDict = ObjectToDictionary(constraints); |
140 | | - constraintsDict.Add(ClientRouteTokenName, new SpaRouteConstraint()); |
141 | | - |
142 | | - routeBuilder.MapRoute(name, template, defaults, constraintsDict, dataTokens); |
143 | | - } |
144 | | - |
145 | | - private static string CreateRouteTemplate(string templatePrefix) |
146 | | - { |
147 | | - templatePrefix = templatePrefix ?? string.Empty; |
148 | | - |
149 | | - if (templatePrefix.Contains("?")) { |
150 | | - // TODO: Consider supporting this. The {*clientRoute} part should be added immediately before the '?' |
151 | | - throw new ArgumentException("SPA fallback route templates don't support querystrings"); |
152 | | - } |
153 | | - |
154 | | - if (templatePrefix.Contains("#")) { |
155 | | - throw new ArgumentException("SPA fallback route templates should not include # characters. The hash part of a URI does not get sent to the server."); |
156 | | - } |
157 | | - |
158 | | - if (templatePrefix != string.Empty && !templatePrefix.EndsWith("/")) { |
159 | | - templatePrefix += "/"; |
160 | | - } |
161 | | - |
162 | | - return templatePrefix + $"{{*{ ClientRouteTokenName }}}"; |
163 | | - } |
164 | | - |
165 | | - private static IDictionary<string, object> ObjectToDictionary(object value) |
166 | | - { |
167 | | - return value as IDictionary<string, object> ?? new RouteValueDictionary(value); |
168 | | - } |
169 | | - |
170 | | - private class SpaRouteConstraint : IRouteConstraint |
171 | | - { |
172 | | - public bool Match(HttpContext httpContext, IRouter route, string routeKey, IDictionary<string, object> values, RouteDirection routeDirection) |
173 | | - { |
174 | | - var clientRouteValue = (values[ClientRouteTokenName] as string) ?? string.Empty; |
175 | | - return !HasDotInLastSegment(clientRouteValue); |
176 | | - } |
177 | | - |
178 | | - private bool HasDotInLastSegment(string uri) |
179 | | - { |
180 | | - var lastSegmentStartPos = uri.LastIndexOf('/'); |
181 | | - return uri.IndexOf('.', lastSegmentStartPos + 1) >= 0; |
182 | | - } |
183 | | - } |
184 | | - } |
185 | 126 | } |
0 commit comments