Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aspnetcore/blazor/components/quickgrid.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ In the following example:

### Close `QuickGrid` column options

Close the `QuickGrid` column options UI with the `CloseColumnOptionsAsync` method.
Close the `QuickGrid` column options UI with the `HideColumnOptionsAsync` method.

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

Expand All @@ -237,7 +237,7 @@ The following example closes the column options UI as soon as the title filter i
<PropertyColumn Property="@(m => m.Title)" Title="Title">
<ColumnOptions>
<input type="search" @bind="titleFilter" placeholder="Filter by title"
@bind:after="@(() => movieGrid.CloseColumnOptionsAsync())" />
@bind:after="@(() => movieGrid.HideColumnOptionsAsync())" />
</ColumnOptions>
</PropertyColumn>
<PropertyColumn Property="@(m => m.Genre)" Title="Genre" />
Expand Down
127 changes: 126 additions & 1 deletion aspnetcore/blazor/fundamentals/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,25 @@ Slashes and segments of the captured path are decoded. For a route template of `

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.

:::moniker range=">= aspnetcore-8.0"
:::moniker range=">= aspnetcore-10.0"

<!-- UPDATE 10.0 - API doc cross-links -->

Member | Description
--- | ---
<xref:Microsoft.AspNetCore.Components.NavigationManager.Uri> | Gets the current absolute URI.
<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)).
<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>
<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.
`NotFound` | Called to handle scenarios where a requested resource isn't found. For more information, see the [Not Found responses](#not-found-responses) section.
<xref:Microsoft.AspNetCore.Components.NavigationManager.ToAbsoluteUri%2A> | Converts a relative URI into an absolute URI.
<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.
[`RegisterLocationChangingHandler`](#handleprevent-location-changes) | Registers a handler to process incoming navigation events. Calling <xref:Microsoft.AspNetCore.Components.NavigationManager.NavigateTo%2A> always invokes the handler.
<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.

:::moniker-end

:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

Member | Description
--- | ---
Expand Down Expand Up @@ -684,6 +702,113 @@ The following component:

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

:::moniker range=">= aspnetcore-10.0"

## Not Found responses

<!-- UPDATE 10.0 - API doc cross-links -->

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

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

* **Static SSR**: Calling `NotFound` sets the HTTP status code to 404.
* **Streaming rendering**: Throws an exception if the response has already started.
* **Interactive rendering**: Signals the Blazor router ([`Router` component](xref:blazor/fundamentals/routing#route-templates)) to render Not Found content.

When a component is rendered statically (static SSR) and `NavigationManager.NotFound` is called, the 404 status code is set on the response:

```razor
@page "/render-not-found-ssr"
@inject NavigationManager Navigation

@code {
protected override void OnInitialized()
{
Navigation.NotFound();
}
}
```

Two approaches for providing Not Found content for global interactive rendering:

* Use a Not Found page (Razor component).
* 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).

The following example uses a Not Found page (`NotFoundPage` component) to render Not Found content.

`NotFoundPage.razor`:

```razor
<h1>Not Found</h1>

<p>Sorry! Nothing to show.</p>
```

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

```razor
<Router ...>
<Found ...>
...
</Found>
<NotFound>
<NotFoundPage />
</NotFound>
</Router>
```

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:

```razor
@page "/render-not-found-interactive"
@inject NavigationManager Navigation

@if (RendererInfo.IsInteractive)
{
<button @onclick="TriggerNotFound">Trigger Not Found</button>
}

@code {
private void TriggerNotFound()
{
Navigation.NotFound();
}
}
```

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.

`Routes.razor`:

```razor
@inject NavigationManager Navigation
@inject ILogger<Routes> Logger

<Router AppAssembly="typeof(Program).Assembly" NotFound="renderFragment">
<Found Context="routeData">
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="routeData" Selector="h1" />
</Found>
</Router>

@code {
private RenderFragment renderFragment =
@<div><h1>Not Found</h1><p>Sorry! Nothing to show.</p></div>;

protected override void OnInitialized() => Navigation.OnNotFound += OnNotFound;

private void OnNotFound(object? sender, EventArgs args)
{
Logger.LogError("Something wasn't found!");
}

public void Dispose() => Navigation.OnNotFound -= OnNotFound;
}
```

:::moniker-end

:::moniker range=">= aspnetcore-8.0"

## Enhanced navigation and form handling
Expand Down
4 changes: 2 additions & 2 deletions aspnetcore/blazor/fundamentals/static-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ The following configuration must be present in the `wwwwoot/index.html` file of
</html>
```

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

```xml
<PropertyGroup>
<WriteImportMapToHtml>true</WriteImportMapToHtml>
<OverrideHtmlAssetPlaceholders>true</OverrideHtmlAssetPlaceholders>
</PropertyGroup>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Property | Default | Set value to&hellip; | Description
`<WasmNativeStrip>` | `true` | `false` | Controls stripping the native executable.
`<WasmNativeDebugSymbols>` | `true` | `true` | Controls building with native debug symbols.

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

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

Expand Down
36 changes: 24 additions & 12 deletions aspnetcore/release-notes/aspnetcore-10/includes/blazor.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ For more information, see <xref:blazor/fundamentals/routing#navlink-component>.

### Close `QuickGrid` column options

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

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

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

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.

<!-- UNCOMMENT FOR PREVIEW 4? ...
<!-- UNCOMMENT FOR PREVIEW 5 ...
Waiting on https://github.com/dotnet/runtime/issues/97449
... and update the Call web API article Line 983

Expand Down Expand Up @@ -147,7 +147,7 @@ The following markup must be present in the `wwwwoot/index.html` file to adopt t
</html>
```

In the project file (`.csproj`), add the `<WriteImportMapToHtml>` property set to `true`:
In the project file (`.csproj`), add the `<OverrideHtmlAssetPlaceholders>` property set to `true`:

```diff
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
Expand All @@ -156,7 +156,7 @@ In the project file (`.csproj`), add the `<WriteImportMapToHtml>` property set t
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
+ <WriteImportMapToHtml>true</WriteImportMapToHtml>
+ <OverrideHtmlAssetPlaceholders>true</OverrideHtmlAssetPlaceholders>
</PropertyGroup>
</Project>
```
Expand Down Expand Up @@ -289,8 +289,6 @@ else

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

<!-- PREVIEW 4

### New JavaScript interop features

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

## Preloaded Blazor framework static assets
### Preloaded Blazor framework static assets

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.

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

## `NavigationManager.NavigateTo` no longer throws a `NavigationException`
### `NavigationManager.NavigateTo` no longer throws a `NavigationException`

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.

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.

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.

!!!!!!!!! HOLD THE NEXT BIT FOR PREVIEW 5 !!!!!!!!!
<!-- HOLD FOR PREVIEW 5

To revert to the previous behavior of throwing a <xref:Microsoft.AspNetCore.Components.NavigationException>, set the following <xref:System.AppContext> switch:

```csharp
AppContext.SetSwitch(
"Microsoft.AspNetCore.Components.Endpoints.NavigationManager.EnableThrowNavigationException",
isEnabled: true);
```
!!!!!!!!! HOLD END !!!!!!!!!

-->

### Not Found responses using `NavigationManager` for static SSR and global interactive rendering

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:

* **Static server-side rendering (static SSR)**: Calling `NotFound` sets the HTTP status code to 404.
* **Streaming rendering**: Throws an exception if the response has already started.
* **Interactive rendering**: Signals the Blazor router ([`Router` component](xref:blazor/fundamentals/routing#route-templates)) to render Not Found content.

Per-page/component rendering support is planned for Preview 5 in June, 2025.

You can use the `NavigationManager.OnNotFound` event for notifications when `NotFound` is invoked.

For more information and examples, see <xref:blazor/fundamentals/routing?view=aspnetcore-10.0#not-found-responses>.