From 9bb4aff54940a4f8072b64e6a8df534bccdd0306 Mon Sep 17 00:00:00 2001 From: Howard Richards Date: Thu, 13 Apr 2023 18:03:53 +0100 Subject: [PATCH] Fixes #31 - Blazor components can support multiple `@page` directives --- .../Proxy/BlazorRouteDiscovery.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/main/src/ReCode.Cocoon.Proxy/Proxy/BlazorRouteDiscovery.cs b/main/src/ReCode.Cocoon.Proxy/Proxy/BlazorRouteDiscovery.cs index 874bcfc..c9d78d4 100644 --- a/main/src/ReCode.Cocoon.Proxy/Proxy/BlazorRouteDiscovery.cs +++ b/main/src/ReCode.Cocoon.Proxy/Proxy/BlazorRouteDiscovery.cs @@ -1,7 +1,8 @@ -using System; +using Microsoft.AspNetCore.Components; +using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; -using Microsoft.AspNetCore.Components; namespace ReCode.Cocoon.Proxy.Proxy { @@ -14,11 +15,15 @@ public static IEnumerable FindRoutes(Type type) { if (exportedType.BaseType?.Name == "ComponentBase") { - var routeAttribute = exportedType - .GetCustomAttribute(typeof(RouteAttribute)) - as RouteAttribute; - if (routeAttribute is null) continue; - yield return routeAttribute.Template; + // fix #31 - support multiple routeAttribute values + var routeAttributes = exportedType.GetCustomAttributes(typeof(RouteAttribute)) + .Select(a => a as RouteAttribute); + if (!routeAttributes.Any()) continue; + foreach (var routeAttribute in routeAttributes) + { + if (routeAttribute != null) + yield return routeAttribute.Template; + } } } }