Skip to content

Commit d55c12c

Browse files
authored
[11.0 P1] NavigateTo and NavLink support RelativeToCurrentUri (#36750)
1 parent e2ee8cd commit d55c12c

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

aspnetcore/blazor/fundamentals/navigation.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,24 @@ There are two <xref:Microsoft.AspNetCore.Components.Routing.NavLinkMatch> option
7878

7979
:::moniker-end
8080

81+
:::moniker range=">= aspnetcore-11.0"
82+
83+
<!-- UPDATE 11.0 - API cross-link
84+
85+
<xref:Microsoft.AspNetCore.Components.Routing.NavLink.RelativeToCurrentUri?displayProperty=nameWithType>
86+
87+
-->
88+
89+
Set `NavLink.RelativeToCurrentUri` to `true` to resolve the `href` relative to the current page path instead of the app's base URI:
90+
91+
```razor
92+
<NavLink href="details" RelativeToCurrentUri="true">View Details</NavLink>
93+
```
94+
95+
If the current URI is `/docs/getting-started/installation`, the preceding link navigates to `/docs/getting-started/details`.
96+
97+
:::moniker-end
98+
8199
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:
82100

83101
```razor
@@ -751,9 +769,45 @@ The <xref:Microsoft.AspNetCore.Components.NavigationManager> uses the browser's
751769

752770
Pass <xref:Microsoft.AspNetCore.Components.NavigationOptions> to <xref:Microsoft.AspNetCore.Components.NavigationManager.NavigateTo%2A> to control the following behaviors:
753771

772+
:::moniker-end
773+
774+
:::moniker range=">= aspnetcore-11.0"
775+
776+
<!-- UPDATE 11.0 - API cross-link
777+
778+
<xref:Microsoft.AspNetCore.Components.NavigationOptions.RelativeToCurrentUri>
779+
780+
-->
781+
754782
* <xref:Microsoft.AspNetCore.Components.NavigationOptions.ForceLoad>: Bypass client-side routing and force the browser to load the new page from the server, whether or not the URI is handled by the client-side router. The default value is `false`.
755783
* <xref:Microsoft.AspNetCore.Components.NavigationOptions.ReplaceHistoryEntry>: Replace the current entry in the history stack. If `false`, append the new entry to the history stack. The default value is `false`.
756784
* <xref:Microsoft.AspNetCore.Components.NavigationOptions.HistoryEntryState>: Gets or sets the state to append to the history entry.
785+
* `RelativeToCurrentUri`: When `true`, the URI is resolved relative to the current page path instead of the app's base URI. The default value is `false`.
786+
787+
In the following example:
788+
789+
* The state appended to the history entry is "`Navigation state`."
790+
* If the current URI is `/docs/getting-started/installation`, navigation results in a request for `/docs/getting-started/configuration`.
791+
792+
```csharp
793+
Navigation.NavigateTo("/configuration", new NavigationOptions
794+
{
795+
HistoryEntryState = "Navigation state",
796+
RelativeToCurrentUri = true
797+
});
798+
```
799+
800+
For more information on obtaining the state associated with the target history entry while handling location changes, see the [Handle/prevent location changes](#handleprevent-location-changes) section.
801+
802+
:::moniker-end
803+
804+
:::moniker range=">= aspnetcore-7.0 < aspnetcore-11.0"
805+
806+
* <xref:Microsoft.AspNetCore.Components.NavigationOptions.ForceLoad>: Bypass client-side routing and force the browser to load the new page from the server, whether or not the URI is handled by the client-side router. The default value is `false`.
807+
* <xref:Microsoft.AspNetCore.Components.NavigationOptions.ReplaceHistoryEntry>: Replace the current entry in the history stack. If `false`, append the new entry to the history stack. The default value is `false`.
808+
* <xref:Microsoft.AspNetCore.Components.NavigationOptions.HistoryEntryState>: Gets or sets the state to append to the history entry.
809+
810+
In the following example, the state appended to the history entry is "`Navigation state`."
757811

758812
```csharp
759813
Navigation.NavigateTo("/path", new NavigationOptions

0 commit comments

Comments
 (0)