fix app-active tag helper

This commit is contained in:
2022-12-14 15:17:13 +01:00
parent 56d1e3f804
commit 727e641cf5
+5 -5
View File
@@ -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<string> classes = Classes?.Split(" ").ToHashSet() ?? new HashSet<string>();
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");
}