-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Ignore query/fragment in ShouldMatch
of NavLink
by default but allow overriding ShouldMatch
#59903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
825ea4c
Fix that is missing change to docs.
ilonatommy 5a6caeb
Revert previous approach, allow custom ShouldMatch implementations.
ilonatommy eecf253
Fix: Missing XML comment for publicly visible type or member.
ilonatommy 882e494
Revert unrelated test.
ilonatommy eda0dd0
Fix test with fragments - redirection has to be made from an orgin th…
ilonatommy 46e9c36
Breaking change: NavLinkMatch.All matches queries and fragments with …
ilonatommy de2ee78
Fix test: the order of links matters.
ilonatommy 863ce4a
App context switch to disable the update.
ilonatommy 181047c
Feedback.
ilonatommy 17ece19
Merge remote-tracking branch 'origin/main' into fix-31312
ilonatommy 0c7f19a
Feedback - avoid allocating a string.
ilonatommy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
#nullable enable | ||
virtual Microsoft.AspNetCore.Components.Routing.NavLink.ShouldMatch(string! currentUriAbsolute) -> bool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/Components/test/testassets/BasicTestApp/RouterTest/LayoutOverridden.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@page "/layout-overridden" | ||
@page "/layout-overridden/for-hash" | ||
@layout RouterTestLayoutNavLinksOverridden | ||
<div id="test-info">This is the page with overridden layout.</div> |
18 changes: 18 additions & 0 deletions
18
src/Components/test/testassets/BasicTestApp/RouterTest/LinksOverridden.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@using Microsoft.AspNetCore.Components.Routing | ||
<style type="text/css"> | ||
a.active { | ||
background-color: yellow; | ||
font-weight: bold; | ||
} | ||
</style> | ||
<ul> | ||
<li><NavLinkIgnoreQueryAndFragmentString href="/subdir/layout-overridden/" Match=NavLinkMatch.All>Override layout (matches all)</NavLinkIgnoreQueryAndFragmentString></li> | ||
<li><NavLinkIgnoreQueryAndFragmentString href="/subdir/layout-overridden" Match=NavLinkMatch.All>Override layout, no trailing slash (matches all)</NavLinkIgnoreQueryAndFragmentString></li> | ||
<li><NavLinkIgnoreQueryAndFragmentString href="/subdir/layout-overridden/?abc=123">Override layout with query</NavLinkIgnoreQueryAndFragmentString></li> | ||
<li><NavLinkIgnoreQueryAndFragmentString href="/subdir/layout-overridden?abc=123">Override layout with query, no trailing slash</NavLinkIgnoreQueryAndFragmentString></li> | ||
<li><NavLinkIgnoreQueryAndFragmentString href="/subdir/layout-overridden/#blah">Override layout with hash</NavLinkIgnoreQueryAndFragmentString></li> | ||
<li><NavLinkIgnoreQueryAndFragmentString href="/subdir/layout-overridden#blah">Override layout with hash, no trailing slash</NavLinkIgnoreQueryAndFragmentString></li> | ||
<li><NavLinkIgnoreQueryAndFragmentString href="/subdir/layout-overridden/Default.html">Override layout with extension</NavLinkIgnoreQueryAndFragmentString></li> | ||
<li><NavLinkIgnoreQueryAndFragmentString href="/subdir/layout-overridden/Other">Override Other</NavLinkIgnoreQueryAndFragmentString></li> | ||
<li><NavLinkIgnoreQueryAndFragmentString href="/subdir/Other" Match=NavLinkMatch.All>Override Other with base-relative URL (matches all)</NavLinkIgnoreQueryAndFragmentString></li> | ||
</ul> |
27 changes: 27 additions & 0 deletions
27
...ponents/test/testassets/BasicTestApp/RouterTest/NavLinkIgnoreQueryAndFragmentString.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
@using Microsoft.AspNetCore.Components.Routing; | ||
@inherits NavLink | ||
|
||
@{ | ||
base.BuildRenderTree(__builder); | ||
} | ||
|
||
@code{ | ||
|
||
protected override bool ShouldMatch(string currentUriAbsolute) | ||
{ | ||
if (base.ShouldMatch(currentUriAbsolute)) | ||
{ | ||
return true; | ||
} | ||
|
||
var originalMatch = base.Match; | ||
base.Match = NavLinkMatch.All; | ||
string uriWithoutQueryAndFragment = GetUriIgnoreQueryAndFragment(currentUriAbsolute); | ||
var shouldMatch = base.ShouldMatch(uriWithoutQueryAndFragment); | ||
base.Match = originalMatch; | ||
return shouldMatch; | ||
} | ||
|
||
private string GetUriIgnoreQueryAndFragment(string uri) => | ||
new Uri(uri).GetLeftPart(UriPartial.Path); | ||
} | ||
ilonatommy marked this conversation as resolved.
Show resolved
Hide resolved
|
6 changes: 6 additions & 0 deletions
6
src/Components/test/testassets/BasicTestApp/RouterTestLayoutNavLinksOverridden.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@using Microsoft.AspNetCore.Components | ||
@inherits LayoutComponentBase | ||
|
||
@Body | ||
|
||
<BasicTestApp.RouterTest.LinksOverridden /> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.