Skip to content

Commit 825ea4c

Browse files
committed
Fix that is missing change to docs.
1 parent dc2a6fe commit 825ea4c

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/Components/Web/src/Routing/NavLink.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,33 @@ private bool ShouldMatch(string currentUriAbsolute)
124124
return true;
125125
}
126126

127+
if (Match == NavLinkMatch.All
128+
&& IsStrictlyPrefixIgnoringQueryAndFragment(currentUriAbsolute))
129+
{
130+
return true;
131+
}
132+
133+
return false;
134+
}
135+
136+
private bool IsStrictlyPrefixIgnoringQueryAndFragment(string currentUriAbsolute)
137+
{
138+
Debug.Assert(_hrefAbsolute != null);
139+
140+
return IsStrictlyPrefixedIgnoringSuffixAfterSymbol(currentUriAbsolute, '?')
141+
|| IsStrictlyPrefixedIgnoringSuffixAfterSymbol(currentUriAbsolute, '#');
142+
}
143+
144+
private bool IsStrictlyPrefixedIgnoringSuffixAfterSymbol(string currentUriAbsolute, char symbol)
145+
{
146+
Debug.Assert(_hrefAbsolute != null);
147+
148+
var fragmentIndex = currentUriAbsolute.IndexOf(symbol);
149+
if (fragmentIndex >= 0)
150+
{
151+
var prefix = currentUriAbsolute.Substring(0, fragmentIndex);
152+
return IsStrictlyPrefixWithSeparator(currentUriAbsolute, prefix);
153+
}
127154
return false;
128155
}
129156

@@ -199,7 +226,7 @@ private static bool IsStrictlyPrefixWithSeparator(string value, string prefix)
199226

200227
private static bool IsUnreservedCharacter(char c)
201228
{
202-
// Checks whether it is an unreserved character according to
229+
// Checks whether it is an unreserved character according to
203230
// https://datatracker.ietf.org/doc/html/rfc3986#section-2.3
204231
// Those are characters that are allowed in a URI but do not have a reserved
205232
// purpose (e.g. they do not separate the components of the URI)

src/Components/test/E2ETest/Tests/StandaloneAppTest.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,30 @@ public void NavMenuHighlightsCurrentLocation()
6464
item => Assert.Equal("Home", item.Text.Trim()));
6565
}
6666

67+
[Fact]
68+
public void NavMenuWithMatchLinkAllHighlightsCurrentLocationIgnoringQueryAndFragment()
69+
{
70+
var activeNavLinksSelector = By.CssSelector(".sidebar a.active");
71+
var mainHeaderSelector = By.TagName("h1");
72+
73+
// Verify we start at home, with the home link highlighted
74+
Assert.Equal("Hello, world!", Browser.Exists(mainHeaderSelector).Text);
75+
Assert.Collection(Browser.FindElements(activeNavLinksSelector),
76+
item => Assert.Equal("Home", item.Text.Trim()));
77+
78+
// Navigate to Home page with an ignorable query
79+
Navigate("/?CourseId=123456");
80+
var collection1 = Browser.FindElements(activeNavLinksSelector);
81+
Assert.Collection(collection1,
82+
item => Assert.Equal("Home", item.Text.Trim()));
83+
84+
// Navigate to Home page with an ignorable fragment
85+
Navigate("/#section-123456");
86+
var collection2 = Browser.FindElements(activeNavLinksSelector);
87+
Assert.Collection(collection2,
88+
item => Assert.Equal("Home", item.Text.Trim()));
89+
}
90+
6791
[Fact]
6892
public void HasCounterPage()
6993
{

0 commit comments

Comments
 (0)