-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Ignore query/fragment in ShouldMatch
of NavLink
by default but allow overriding ShouldMatch
#59903
base: main
Are you sure you want to change the base?
Conversation
NavLink.All
on "\" location does not match urls with queries nor fragmentsNavLink.All
should match urls with queries and fragments
The option of exposing |
NavLink.All
should match urls with queries and fragmentsNavLink
's ShouldMatch
method
...Components/test/testassets/BasicTestApp/RouterTest/NavLinkIgnoreQueryAndFragmentString.razor
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks great.
Some comments:
- I'm not opposed to us exposing ShouldMatch, but I'm not sure how much it's needed.
- I believe that we should fix this in NavLink directly.
- I find hard to believe that relying on not matching on the query string is a behavior people will have taken a dependency on, especially since the way we compare is extremely unpredictable, as the query string parameters need to be on the same exact order every time.
- At most we can consider an
AppCompatSwitch
to revert to the old behavior
@SteveSandersonMS in case you have strong opinions about it. I think the original intent of Match.Prefix
and Match.All
was to match based on the path, and that we didn't account for the query string or the hash at the time.
It doesn't make sense to do matching on exact urls on something containing a query string because query string parameters are not ordered
So for example, /a/b?c=d&e=f is the same url as /a/b?e=f&c=d, it doesn't make sense that if the link is for the first url, it doesn't match the second
The original intent was focused on the case where you have links to
... and you want:
Treating There is possibly a case where the change would be bad, e.g., if you had a tabview with links like:
Now if If we were building things from scratch here I'd be comfortable defaulting to "ignore query/hash" and force people who want distinguishable links to |
@SteveSandersonMS thanks for the input. I think we should go ahead and make the change now with a breaking change announcement and if we want to be extra careful, an app compat switch. I think it'll be more common for people to trip into the current behavior than for the second case to apply. |
NavLink
's ShouldMatch
methodShouldMatch
of NavLink
by default but allow overriding ShouldMatch
…an option to override this behavior.
Breaking change to the behavior of
ShouldMatch
method inNavLink
Description
Appending a query to home url that is marked as
NavLink.All
in the navigation layout, resulted in un-selecting it in the navigation tab. This was reported as confusing for the users.In #32168 a property to skip query in the uri comparison was proposed, but it does not solve such cases as appended fragments etc. After the discussion (see below), it was decided that the original intention of
NavLink.All
wasn't matching queries and we should start ignoring them. This may break a possibly few apps that relied on the previous behavior, so we are exposingShouldMatch
for inheritance. Users can create their own version ofNavLink
, e.g.NavLinkIgnoreQueryAndFragmentString
(see tests).Fixes #31312.