From 727e641cf59e21524def14404a9b94068a91c85b Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Wed, 14 Dec 2022 15:17:13 +0100 Subject: [PATCH] fix app-active tag helper --- zero/TagHelpers/ActiveTagHelper.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/zero/TagHelpers/ActiveTagHelper.cs b/zero/TagHelpers/ActiveTagHelper.cs index 6b71d9dd..80ead1f2 100644 --- a/zero/TagHelpers/ActiveTagHelper.cs +++ b/zero/TagHelpers/ActiveTagHelper.cs @@ -11,9 +11,6 @@ public class ActiveTagHelper : TagHelper [HtmlAttributeName("class")] public string Classes { get; set; } - [HtmlAttributeName("href")] - public string Href { get; set; } - public override int Order => 100; @@ -27,13 +24,16 @@ public class ActiveTagHelper : TagHelper { output.Attributes.RemoveAll("app-active"); + output.Attributes.TryGetAttribute("Href", out TagHelperAttribute _href); + string href = _href?.Value?.ToString() ?? string.Empty; + HashSet classes = Classes?.Split(" ").ToHashSet() ?? new HashSet(); - if (_httpContextAccessor.HttpContext.IsPartOfUrl(Href)) + if (_httpContextAccessor.HttpContext.IsPartOfUrl(href)) { classes.Add("is-active"); } - if (_httpContextAccessor.HttpContext.IsUrl(Href)) + if (_httpContextAccessor.HttpContext.IsUrl(href)) { classes.Add("is-active-exact"); }