You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/blazor/fundamentals/routing.md
+126-1Lines changed: 126 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -571,7 +571,25 @@ Slashes and segments of the captured path are decoded. For a route template of `
571
571
572
572
Use <xref:Microsoft.AspNetCore.Components.NavigationManager> to manage URIs and navigation in C# code. <xref:Microsoft.AspNetCore.Components.NavigationManager> provides the event and methods shown in the following table.
573
573
574
-
:::moniker range=">= aspnetcore-8.0"
574
+
:::moniker range=">= aspnetcore-10.0"
575
+
576
+
<!-- UPDATE 10.0 - API doc cross-links -->
577
+
578
+
Member | Description
579
+
--- | ---
580
+
<xref:Microsoft.AspNetCore.Components.NavigationManager.Uri> | Gets the current absolute URI.
581
+
<xref:Microsoft.AspNetCore.Components.NavigationManager.BaseUri> | Gets the base URI (with a trailing slash) that can be prepended to relative URI paths to produce an absolute URI. Typically, <xref:Microsoft.AspNetCore.Components.NavigationManager.BaseUri> corresponds to the `href` attribute on the document's `<base>` element ([location of `<head>` content](xref:blazor/project-structure#location-of-head-and-body-content)).
582
+
<xref:Microsoft.AspNetCore.Components.NavigationManager.NavigateTo%2A> | Navigates to the specified URI. If `forceLoad` is `false`:<ul><li>And enhanced navigation is available at the current URL, Blazor's enhanced navigation is activated.</li><li>Otherwise, Blazor performs a full-page reload for the requested URL.</li></ul>If `forceLoad` is `true`:<ul><li>Client-side routing is bypassed.</li><li>The browser is forced to load the new page from the server, whether or not the URI is normally handled by the client-side interactive router.</li></ul><p>For more information, see the [Enhanced navigation and form handling](#enhanced-navigation-and-form-handling) section.</p><p>If `replace` is `true`, the current URI in the browser history is replaced instead of pushing a new URI onto the history stack.</p>
583
+
<xref:Microsoft.AspNetCore.Components.NavigationManager.LocationChanged> | An event that fires when the navigation location has changed. For more information, see the [Location changes](#location-changes) section.
584
+
`NotFound` | Called to handle scenarios where a requested resource isn't found. For more information, see the [Not Found responses](#not-found-responses) section.
585
+
<xref:Microsoft.AspNetCore.Components.NavigationManager.ToAbsoluteUri%2A> | Converts a relative URI into an absolute URI.
586
+
<xref:Microsoft.AspNetCore.Components.NavigationManager.ToBaseRelativePath%2A> | Based on the app's base URI, converts an absolute URI into a URI relative to the base URI prefix. For an example, see the [Produce a URI relative to the base URI prefix](#produce-a-uri-relative-to-the-base-uri-prefix) section.
587
+
[`RegisterLocationChangingHandler`](#handleprevent-location-changes) | Registers a handler to process incoming navigation events. Calling <xref:Microsoft.AspNetCore.Components.NavigationManager.NavigateTo%2A> always invokes the handler.
588
+
<xref:Microsoft.AspNetCore.Components.NavigationManagerExtensions.GetUriWithQueryParameter%2A> | Returns a URI constructed by updating <xref:Microsoft.AspNetCore.Components.NavigationManager.Uri?displayProperty=nameWithType> with a single parameter added, updated, or removed. For more information, see the [Query strings](#query-strings) section.
For more information on component disposal, see <xref:blazor/components/component-disposal>.
686
704
705
+
:::moniker range=">= aspnetcore-10.0"
706
+
707
+
## Not Found responses
708
+
709
+
<!-- UPDATE 10.0 - API doc cross-links -->
710
+
711
+
*In ASP.NET Core 10.0 Preview 4, Not Found responses are only available for static SSR and global interactive rendering. Per-page/component rendering support is planned for Preview 5 in June, 2025.*
712
+
713
+
<xref:Microsoft.AspNetCore.Components.NavigationManager> provides a `NotFound` method to handle scenarios where a requested resource isn't found during static server-side rendering (static SSR) or global interactive rendering:
714
+
715
+
***Static SSR**: Calling `NotFound` sets the HTTP status code to 404.
716
+
***Streaming rendering**: Throws an exception if the response has already started.
717
+
***Interactive rendering**: Signals the Blazor router ([`Router` component](xref:blazor/fundamentals/routing#route-templates)) to render Not Found content.
718
+
719
+
When a component is rendered statically (static SSR) and `NavigationManager.NotFound` is called, the 404 status code is set on the response:
720
+
721
+
```razor
722
+
@page "/render-not-found-ssr"
723
+
@inject NavigationManager Navigation
724
+
725
+
@code {
726
+
protected override void OnInitialized()
727
+
{
728
+
Navigation.NotFound();
729
+
}
730
+
}
731
+
```
732
+
733
+
Two approaches for providing Not Found content for global interactive rendering:
734
+
735
+
* Use a Not Found page (Razor component).
736
+
* Specify Not Found content in the [`Router` component's](xref:blazor/fundamentals/routing#route-templates)<xref:Microsoft.AspNetCore.Components.Routing.Router.NotFound%2A> property (`<NotFound>...</NotFound>` markup or by setting the `NotFound` parameter to a render fragment in C# code).
737
+
738
+
The following example uses a Not Found page (`NotFoundPage` component) to render Not Found content.
739
+
740
+
`NotFoundPage.razor`:
741
+
742
+
```razor
743
+
<h1>Not Found</h1>
744
+
745
+
<p>Sorry! Nothing to show.</p>
746
+
```
747
+
748
+
Specify the `NotFoundPage` component to the `Router` component in `Routes.razor`. You might need to specify the component's namespace with an [`@using`](xref:mvc/views/razor#using) directive either at the top of the `Routes.razor` file or in an [`_Imports.razor` file](xref:blazor/components/index#component-name-class-name-and-namespace).
749
+
750
+
```razor
751
+
<Router ...>
752
+
<Found ...>
753
+
...
754
+
</Found>
755
+
<NotFound>
756
+
<NotFoundPage />
757
+
</NotFound>
758
+
</Router>
759
+
```
760
+
761
+
When a component is rendered with a global interactive render mode, calling `NotFound` signals the Blazor router to render Not Found content, which is the `NotFoundPage` component:
762
+
763
+
```razor
764
+
@page "/render-not-found-interactive"
765
+
@inject NavigationManager Navigation
766
+
767
+
@if (RendererInfo.IsInteractive)
768
+
{
769
+
<button @onclick="TriggerNotFound">Trigger Not Found</button>
770
+
}
771
+
772
+
@code {
773
+
private void TriggerNotFound()
774
+
{
775
+
Navigation.NotFound();
776
+
}
777
+
}
778
+
```
779
+
780
+
You can use the `OnNotFound` event for notifications when `NotFound` is invoked. The following example uses a render fragment (<xref:Microsoft.AspNetCore.Components.RenderFragment>) to render the Not Found content.
Copy file name to clipboardExpand all lines: aspnetcore/blazor/performance/webassembly-browser-developer-tools-diagnostics.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -45,7 +45,7 @@ Property | Default | Set value to… | Description
45
45
46
46
Setting the [`Timing-Allow-Origin` HTTP header](https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/Timing-Allow-Origin) allows for more precise time measurements.
47
47
48
-
Enabling profilers has negative size and performance impact, so don't publish an app for production with profilers enabled. In the following example, a condition is set on a property group section that only enables profiling when the app is built with `/p:BlazorSampleProfilingEnabled=true` (.NET CLI) or `<BlazorSampleProfilingEnabled>true</BlazorSampleProfilingEnabled>` in a Visual Studio publish profile, where "`BlazorSampleProfilingEnabled`" is a custom symbol name that you choose and doesn't conflict with other symbol names.
48
+
Enabling profilers has negative size and performance impacts, so don't publish an app for production with profilers enabled. In the following example, a condition is set on a property group section that only enables profiling when the app is built with `/p:BlazorSampleProfilingEnabled=true` (.NET CLI) or `<BlazorSampleProfilingEnabled>true</BlazorSampleProfilingEnabled>` in a Visual Studio publish profile, where "`BlazorSampleProfilingEnabled`" is a custom symbol name that you choose and doesn't conflict with other symbol names.
@@ -96,7 +96,7 @@ In prior Blazor releases, response streaming for <xref:System.Net.Http.HttpClien
96
96
97
97
This is a breaking change because calling <xref:System.Net.Http.HttpContent.ReadAsStreamAsync%2A?displayProperty=nameWithType> for an <xref:System.Net.Http.HttpResponseMessage.Content%2A?displayProperty=nameWithType> (`response.Content.ReadAsStreamAsync()`) returns a `BrowserHttpReadStream` and no longer a <xref:System.IO.MemoryStream>. `BrowserHttpReadStream` doesn't support synchronous operations, such as `Stream.Read(Span<Byte>)`. If your code uses synchronous operations, you can opt-out of response streaming or copy the <xref:System.IO.Stream> into a <xref:System.IO.MemoryStream> yourself.
98
98
99
-
<!-- UNCOMMENT FOR PREVIEW 4? ...
99
+
<!-- UNCOMMENT FOR PREVIEW 5 ...
100
100
Waiting on https://github.com/dotnet/runtime/issues/97449
101
101
... and update the Call web API article Line 983
102
102
@@ -147,7 +147,7 @@ The following markup must be present in the `wwwwoot/index.html` file to adopt t
147
147
</html>
148
148
```
149
149
150
-
In the project file (`.csproj`), add the `<WriteImportMapToHtml>` property set to `true`:
150
+
In the project file (`.csproj`), add the `<OverrideHtmlAssetPlaceholders>` property set to `true`:
State can be serialized for multiple components of the same type, and you can establish declarative state in a service for use around the app by calling `RegisterPersistentService` on the Razor components builder (<xref:Microsoft.Extensions.DependencyInjection.RazorComponentsServiceCollectionExtensions.AddRazorComponents%2A>) with a custom service type and render mode. For more information, see <xref:blazor/components/prerender?view=aspnetcore-10.0#persist-prerendered-state>.
291
291
292
-
<!-- PREVIEW 4
293
-
294
292
### New JavaScript interop features
295
293
296
294
Blazor adds support for the following JS interop features:
@@ -361,28 +359,42 @@ New performance profiling and diagnostic counters are available for Blazor WebAs
In Blazor Web Apps, framework static assets are automatically preloaded using [`Link` headers](https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/Link), which allows the browser to preload resources before the initial page is fetched and rendered. In standalone Blazor WebAssembly apps, framework assets are scheduled for high priority downloading and caching early in browser `index.html` page processing.
367
365
368
366
For more information, see <xref:blazor/fundamentals/static-files?view=aspnetcore-10.0#preloaded-blazor-framework-static-assets>.
369
367
370
-
## `NavigationManager.NavigateTo` no longer throws a `NavigationException`
368
+
###`NavigationManager.NavigateTo` no longer throws a `NavigationException`
371
369
372
370
Previously, calling <xref:Microsoft.AspNetCore.Components.NavigationManager.NavigateTo%2A?displayProperty=nameWithType> during static server-side rendering (SSR) would throw a <xref:Microsoft.AspNetCore.Components.NavigationException>, interrupting execution before being converted to a redirection response. This caused confusion during debugging and was inconsistent with interactive rendering, where code after <xref:Microsoft.AspNetCore.Components.NavigationManager.NavigateTo%2A> continues to execute normally.
373
371
374
372
Calling <xref:Microsoft.AspNetCore.Components.NavigationManager.NavigateTo%2A?displayProperty=nameWithType> during static SSR no longer throws a <xref:Microsoft.AspNetCore.Components.NavigationException>. Instead, it behaves consistently with interactive rendering by performing the navigation without throwing an exception.
375
373
376
374
Code that relied on <xref:Microsoft.AspNetCore.Components.NavigationException> being thrown should be updated. For example, in the default Blazor Identity UI, the `IdentityRedirectManager` previously threw an <xref:System.InvalidOperationException> after calling `RedirectTo` to ensure it wasn't invoked during interactive rendering. This exception and the [`[DoesNotReturn]` attributes](xref:System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute) should now be removed.
377
375
378
-
!!!!!!!!! HOLD THE NEXT BIT FOR PREVIEW 5 !!!!!!!!!
376
+
<!-- HOLD FOR PREVIEW 5
377
+
379
378
To revert to the previous behavior of throwing a <xref:Microsoft.AspNetCore.Components.NavigationException>, set the following <xref:System.AppContext> switch:
### Not Found responses using `NavigationManager` for static SSR and global interactive rendering
389
+
390
+
The <xref:Microsoft.AspNetCore.Components.NavigationManager> now includes a `NotFound` method to handle scenarios where a requested resource isn't found during static server-side rendering (static SSR) or global interactive rendering:
391
+
392
+
***Static server-side rendering (static SSR)**: Calling `NotFound` sets the HTTP status code to 404.
393
+
***Streaming rendering**: Throws an exception if the response has already started.
394
+
***Interactive rendering**: Signals the Blazor router ([`Router` component](xref:blazor/fundamentals/routing#route-templates)) to render Not Found content.
395
+
396
+
Per-page/component rendering support is planned for Preview 5 in June, 2025.
397
+
398
+
You can use the `NavigationManager.OnNotFound` event for notifications when `NotFound` is invoked.
399
+
400
+
For more information and examples, see <xref:blazor/fundamentals/routing?view=aspnetcore-10.0#not-found-responses>.
0 commit comments