Skip to content

Commit 1f77e03

Browse files
authored
[Pre4] Final round of Blazor content/WN updates (#35433)
1 parent 404d510 commit 1f77e03

File tree

5 files changed

+155
-18
lines changed

5 files changed

+155
-18
lines changed

aspnetcore/blazor/components/quickgrid.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ In the following example:
228228

229229
### Close `QuickGrid` column options
230230

231-
Close the `QuickGrid` column options UI with the `CloseColumnOptionsAsync` method.
231+
Close the `QuickGrid` column options UI with the `HideColumnOptionsAsync` method.
232232

233233
The following example closes the column options UI as soon as the title filter is applied:
234234

@@ -237,7 +237,7 @@ The following example closes the column options UI as soon as the title filter i
237237
<PropertyColumn Property="@(m => m.Title)" Title="Title">
238238
<ColumnOptions>
239239
<input type="search" @bind="titleFilter" placeholder="Filter by title"
240-
@bind:after="@(() => movieGrid.CloseColumnOptionsAsync())" />
240+
@bind:after="@(() => movieGrid.HideColumnOptionsAsync())" />
241241
</ColumnOptions>
242242
</PropertyColumn>
243243
<PropertyColumn Property="@(m => m.Genre)" Title="Genre" />

aspnetcore/blazor/fundamentals/routing.md

Lines changed: 126 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,25 @@ Slashes and segments of the captured path are decoded. For a route template of `
571571

572572
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.
573573

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.
589+
590+
:::moniker-end
591+
592+
:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"
575593

576594
Member | Description
577595
--- | ---
@@ -684,6 +702,113 @@ The following component:
684702

685703
For more information on component disposal, see <xref:blazor/components/component-disposal>.
686704

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.
781+
782+
`Routes.razor`:
783+
784+
```razor
785+
@inject NavigationManager Navigation
786+
@inject ILogger<Routes> Logger
787+
788+
<Router AppAssembly="typeof(Program).Assembly" NotFound="renderFragment">
789+
<Found Context="routeData">
790+
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
791+
<FocusOnNavigate RouteData="routeData" Selector="h1" />
792+
</Found>
793+
</Router>
794+
795+
@code {
796+
private RenderFragment renderFragment =
797+
@<div><h1>Not Found</h1><p>Sorry! Nothing to show.</p></div>;
798+
799+
protected override void OnInitialized() => Navigation.OnNotFound += OnNotFound;
800+
801+
private void OnNotFound(object? sender, EventArgs args)
802+
{
803+
Logger.LogError("Something wasn't found!");
804+
}
805+
806+
public void Dispose() => Navigation.OnNotFound -= OnNotFound;
807+
}
808+
```
809+
810+
:::moniker-end
811+
687812
:::moniker range=">= aspnetcore-8.0"
688813

689814
## Enhanced navigation and form handling

aspnetcore/blazor/fundamentals/static-files.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ The following configuration must be present in the `wwwwoot/index.html` file of
254254
</html>
255255
```
256256

257-
In the project file (`.csproj`), the `<WriteImportMapToHtml>` property is set to `true`:
257+
In the project file (`.csproj`), the `<OverrideHtmlAssetPlaceholders>` property is set to `true`:
258258

259259
```xml
260260
<PropertyGroup>
261-
<WriteImportMapToHtml>true</WriteImportMapToHtml>
261+
<OverrideHtmlAssetPlaceholders>true</OverrideHtmlAssetPlaceholders>
262262
</PropertyGroup>
263263
```
264264

aspnetcore/blazor/performance/webassembly-browser-developer-tools-diagnostics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Property | Default | Set value to&hellip; | Description
4545

4646
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.
4747

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.
4949

5050
In the app's project file (`.csproj`):
5151

aspnetcore/release-notes/aspnetcore-10/includes/blazor.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,16 @@ For more information, see <xref:blazor/fundamentals/routing#navlink-component>.
6565

6666
### Close `QuickGrid` column options
6767

68-
You can now close the `QuickGrid` column options UI using the new `CloseColumnOptionsAsync` method.
68+
You can now close the `QuickGrid` column options UI using the new `HideColumnOptionsAsync` method.
6969

70-
The following example uses the `CloseColumnOptionsAsync` method to close the column options UI as soon as the title filter is applied:
70+
The following example uses the `HideColumnOptionsAsync` method to close the column options UI as soon as the title filter is applied:
7171

7272
```razor
7373
<QuickGrid @ref="movieGrid" Items="movies">
7474
<PropertyColumn Property="@(m => m.Title)" Title="Title">
7575
<ColumnOptions>
7676
<input type="search" @bind="titleFilter" placeholder="Filter by title"
77-
@bind:after="@(() => movieGrid.CloseColumnOptionsAsync())" />
77+
@bind:after="@(() => movieGrid.HideColumnOptionsAsync())" />
7878
</ColumnOptions>
7979
</PropertyColumn>
8080
<PropertyColumn Property="@(m => m.Genre)" Title="Genre" />
@@ -96,7 +96,7 @@ In prior Blazor releases, response streaming for <xref:System.Net.Http.HttpClien
9696

9797
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.
9898

99-
<!-- UNCOMMENT FOR PREVIEW 4? ...
99+
<!-- UNCOMMENT FOR PREVIEW 5 ...
100100
Waiting on https://github.com/dotnet/runtime/issues/97449
101101
... and update the Call web API article Line 983
102102
@@ -147,7 +147,7 @@ The following markup must be present in the `wwwwoot/index.html` file to adopt t
147147
</html>
148148
```
149149

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`:
151151

152152
```diff
153153
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
@@ -156,7 +156,7 @@ In the project file (`.csproj`), add the `<WriteImportMapToHtml>` property set t
156156
<TargetFramework>net10.0</TargetFramework>
157157
<Nullable>enable</Nullable>
158158
<ImplicitUsings>enable</ImplicitUsings>
159-
+ <WriteImportMapToHtml>true</WriteImportMapToHtml>
159+
+ <OverrideHtmlAssetPlaceholders>true</OverrideHtmlAssetPlaceholders>
160160
</PropertyGroup>
161161
</Project>
162162
```
@@ -289,8 +289,6 @@ else
289289

290290
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>.
291291

292-
<!-- PREVIEW 4
293-
294292
### New JavaScript interop features
295293

296294
Blazor adds support for the following JS interop features:
@@ -361,28 +359,42 @@ New performance profiling and diagnostic counters are available for Blazor WebAs
361359
* <xref:blazor/performance/webassembly-browser-developer-tools?view=aspnetcore-10.0>
362360
* <xref:blazor/performance/webassembly-event-pipe?view=aspnetcore-10.0>
363361

364-
## Preloaded Blazor framework static assets
362+
### Preloaded Blazor framework static assets
365363

366364
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.
367365

368366
For more information, see <xref:blazor/fundamentals/static-files?view=aspnetcore-10.0#preloaded-blazor-framework-static-assets>.
369367

370-
## `NavigationManager.NavigateTo` no longer throws a `NavigationException`
368+
### `NavigationManager.NavigateTo` no longer throws a `NavigationException`
371369

372370
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.
373371

374372
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.
375373

376374
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.
377375

378-
!!!!!!!!! HOLD THE NEXT BIT FOR PREVIEW 5 !!!!!!!!!
376+
<!-- HOLD FOR PREVIEW 5
377+
379378
To revert to the previous behavior of throwing a <xref:Microsoft.AspNetCore.Components.NavigationException>, set the following <xref:System.AppContext> switch:
380379
381380
```csharp
382381
AppContext.SetSwitch(
383382
"Microsoft.AspNetCore.Components.Endpoints.NavigationManager.EnableThrowNavigationException",
384383
isEnabled: true);
385384
```
386-
!!!!!!!!! HOLD END !!!!!!!!!
387385
388386
-->
387+
388+
### 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

Comments
 (0)