Skip to content

Commit 1ed7a71

Browse files
committed
Updates
1 parent fc969ab commit 1ed7a71

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

aspnetcore/blazor/fundamentals/navigation.md

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,30 @@ This article explains how to use the <xref:Microsoft.AspNetCore.Components.Routi
2121

2222
Use a <xref:Microsoft.AspNetCore.Components.Routing.NavLink> component in place of HTML hyperlink elements (`<a>`) when creating navigation links. A <xref:Microsoft.AspNetCore.Components.Routing.NavLink> component behaves like an `<a>` element, except it toggles an `active` CSS class based on whether its `href` matches the current URL. The `active` class helps a user understand which page is the active page among the navigation links displayed. Optionally, assign a CSS class name to <xref:Microsoft.AspNetCore.Components.Routing.NavLink.ActiveClass?displayProperty=nameWithType> to apply a custom CSS class to the rendered link when the current route matches the `href`.
2323

24-
:::moniker range=">= aspnetcore-10.0"
25-
26-
There are two <xref:Microsoft.AspNetCore.Components.Routing.NavLinkMatch> options that you can assign to the `Match` attribute of the `<NavLink>` element:
24+
In the `NavMenu` component (`NavMenu.razor`) of a Blazor app created from a Blazor project template:
2725

28-
* <xref:Microsoft.AspNetCore.Components.Routing.NavLinkMatch.All?displayProperty=nameWithType>: The <xref:Microsoft.AspNetCore.Components.Routing.NavLink> is active when it matches the current URL, ignoring the query string and fragment. To include matching on the query string/fragment, use the `Microsoft.AspNetCore.Components.Routing.NavLink.EnableMatchAllForQueryStringAndFragment` [`AppContext` switch](/dotnet/fundamentals/runtime-libraries/system-appcontext) set to `true`.
29-
* <xref:Microsoft.AspNetCore.Components.Routing.NavLinkMatch.Prefix?displayProperty=nameWithType> (*default*): The <xref:Microsoft.AspNetCore.Components.Routing.NavLink> is active when it matches any prefix of the current URL.
26+
```razor
27+
<div class="nav-item px-3">
28+
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
29+
<span class="bi bi-house-door-fill-nav-menu" aria-hidden="true"></span> Home
30+
</NavLink>
31+
</div>
32+
<div class="nav-item px-3">
33+
<NavLink class="nav-link" href="counter">
34+
<span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Counter
35+
</NavLink>
36+
</div>
37+
```
3038

31-
:::moniker-end
39+
In the preceding example, the Home <xref:Microsoft.AspNetCore.Components.Routing.NavLink> `href=""` matches the home URL and only receives the `active` CSS class at the app's default base path (`/`). The second <xref:Microsoft.AspNetCore.Components.Routing.NavLink> receives the `active` class when the user visits the `Counter` component at `/counter`.
3240

33-
:::moniker range="< aspnetcore-10.0"
41+
:::moniker range=">= aspnetcore-10.0"
3442

3543
There are two <xref:Microsoft.AspNetCore.Components.Routing.NavLinkMatch> options that you can assign to the `Match` attribute of the `<NavLink>` element:
3644

37-
* <xref:Microsoft.AspNetCore.Components.Routing.NavLinkMatch.All?displayProperty=nameWithType>: The <xref:Microsoft.AspNetCore.Components.Routing.NavLink> is active when it matches the entire current URL, including the query string and fragment.
45+
* <xref:Microsoft.AspNetCore.Components.Routing.NavLinkMatch.All?displayProperty=nameWithType>: The <xref:Microsoft.AspNetCore.Components.Routing.NavLink> is active when it matches the current URL, ignoring the query string and fragment. To include matching on the query string/fragment, use the `Microsoft.AspNetCore.Components.Routing.NavLink.EnableMatchAllForQueryStringAndFragment` [`AppContext` switch](/dotnet/fundamentals/runtime-libraries/system-appcontext) set to `true`.
3846
* <xref:Microsoft.AspNetCore.Components.Routing.NavLinkMatch.Prefix?displayProperty=nameWithType> (*default*): The <xref:Microsoft.AspNetCore.Components.Routing.NavLink> is active when it matches any prefix of the current URL.
3947

40-
:::moniker-end
41-
42-
In the preceding example, the Home <xref:Microsoft.AspNetCore.Components.Routing.NavLink> `href=""` matches the home URL and only receives the `active` CSS class at the app's default base path (`/`). The second <xref:Microsoft.AspNetCore.Components.Routing.NavLink> receives the `active` class when the user visits any URL with a `component` prefix (for example, `/component` and `/component/another-segment`).
43-
44-
:::moniker range=">= aspnetcore-10.0"
45-
4648
<!-- UPDATE 10.0 - API cross-link -->
4749

4850
To adopt custom matching logic, subclass <xref:Microsoft.AspNetCore.Components.Routing.NavLink> and override its `ShouldMatch` method. Return `true` from the method when you want to apply the `active` CSS class:
@@ -59,6 +61,15 @@ public class CustomNavLink : NavLink
5961

6062
:::moniker-end
6163

64+
:::moniker range="< aspnetcore-10.0"
65+
66+
There are two <xref:Microsoft.AspNetCore.Components.Routing.NavLinkMatch> options that you can assign to the `Match` attribute of the `<NavLink>` element:
67+
68+
* <xref:Microsoft.AspNetCore.Components.Routing.NavLinkMatch.All?displayProperty=nameWithType>: The <xref:Microsoft.AspNetCore.Components.Routing.NavLink> is active when it matches the entire current URL, including the query string and fragment.
69+
* <xref:Microsoft.AspNetCore.Components.Routing.NavLinkMatch.Prefix?displayProperty=nameWithType> (*default*): The <xref:Microsoft.AspNetCore.Components.Routing.NavLink> is active when it matches any prefix of the current URL.
70+
71+
:::moniker-end
72+
6273
Additional <xref:Microsoft.AspNetCore.Components.Routing.NavLink> component attributes are passed through to the rendered anchor tag. In the following example, the <xref:Microsoft.AspNetCore.Components.Routing.NavLink> component includes the `target` attribute:
6374

6475
```razor

0 commit comments

Comments
 (0)