Skip to content

Commit 9b8b944

Browse files
authored
Blazor router NotFound updates (#30329)
1 parent 6da4e2f commit 9b8b944

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed

aspnetcore/blazor/components/control-head-content.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,20 @@ When the [`::after` pseudo-selector](https://developer.mozilla.org/docs/Web/CSS/
113113

114114
## Not found page title
115115

116+
:::moniker range=">= aspnetcore-8.0"
117+
118+
*This section only applies to Blazor WebAssembly apps.*
119+
120+
In Blazor apps created from Blazor WebAssembly project template, the `NotFound` component template in the `App` component (`App.razor`) sets the page title to `Not found`.
121+
122+
:::moniker-end
123+
124+
:::moniker range="< aspnetcore-8.0"
125+
116126
In Blazor apps created from Blazor project templates, the `NotFound` component template in the `App` component (`App.razor`) sets the page title to `Not found`.
117127

128+
:::moniker-end
129+
118130
`App.razor`:
119131

120132
```razor

aspnetcore/blazor/components/layouts.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ Specifying the layout as a default layout in the `Router` component is a useful
245245

246246
To set a layout for arbitrary Razor template content, specify the layout with a <xref:Microsoft.AspNetCore.Components.LayoutView> component. You can use a <xref:Microsoft.AspNetCore.Components.LayoutView> in any Razor component. The following example sets a layout component named `ErrorLayout` for the `MainLayout` component's <xref:Microsoft.AspNetCore.Components.Routing.Router.NotFound> template (`<NotFound>...</NotFound>`).
247247

248+
:::moniker range=">= aspnetcore-8.0"
249+
250+
> [!NOTE]
251+
> The following example is specifically for a Blazor WebAssembly app because Blazor Web Apps don't use the <xref:Microsoft.AspNetCore.Components.Routing.Router.NotFound> template (`<NotFound>...</NotFound>`). However, the template is supported for backward compatibility to avoid a breaking change in the framework. Blazor Web Apps typically process bad URL requests by either displaying the browser's built-in 404 UI or returning a custom 404 page from the ASP.NET Core server via ASP.NET Core middleware (for example, [`UseStatusCodePagesWithRedirects`](xref:fundamentals/error-handling#usestatuscodepageswithredirects) / [API documentation](xref:Microsoft.AspNetCore.Builder.StatusCodePagesExtensions.UseStatusCodePagesWithRedirects%2A)).
252+
253+
:::moniker-end
254+
248255
`App.razor`:
249256

250257
```razor

aspnetcore/blazor/fundamentals/routing.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,11 @@ When the <xref:Microsoft.AspNetCore.Components.Routing.Router> component navigat
112112

113113
## Provide custom content when content isn't found
114114

115-
<!-- UPDATE 8.0 NotFound isn't part of the BWA template ...
116-
confirm if it's a no-op with SSR/BWA -->
115+
:::moniker range=">= aspnetcore-8.0"
116+
117+
*This section only applies to Blazor WebAssembly apps.* Blazor Web Apps don't use the <xref:Microsoft.AspNetCore.Components.Routing.Router.NotFound> template (`<NotFound>...</NotFound>`), but the template is supported for backward compatibility to avoid a breaking change in the framework. Blazor Web Apps typically process bad URL requests by either displaying the browser's built-in 404 UI or returning a custom 404 page from the ASP.NET Core server via ASP.NET Core middleware (for example, [`UseStatusCodePagesWithRedirects`](xref:fundamentals/error-handling#usestatuscodepageswithredirects) / [API documentation](xref:Microsoft.AspNetCore.Builder.StatusCodePagesExtensions.UseStatusCodePagesWithRedirects%2A)).
118+
119+
:::moniker-end
117120

118121
The <xref:Microsoft.AspNetCore.Components.Routing.Router> component allows the app to specify custom content if content isn't found for the requested route.
119122

aspnetcore/blazor/security/index.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,6 @@ If `user.Identity.IsAuthenticated` is `true`, claims can be enumerated and membe
279279

280280
Set up the `Task<`<xref:Microsoft.AspNetCore.Components.Authorization.AuthenticationState>`>` [cascading parameter](xref:blazor/components/cascading-values-and-parameters) using the <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeRouteView> and <xref:Microsoft.AspNetCore.Components.Authorization.CascadingAuthenticationState> components.
281281

282-
<!-- UPDATE 8.0 Need to confirm this next bit in the BWA world
283-
e.g., did Found survive the NotFound removal? -->
284-
285282
When you create a Blazor app from one of the Blazor project templates with authentication enabled, the app includes the <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeRouteView> and <xref:Microsoft.AspNetCore.Components.Authorization.CascadingAuthenticationState> components shown in the following example. A client-side Blazor app includes the required service registrations as well. Additional information is presented in the [Customize unauthorized content with the Router component](#customize-unauthorized-content-with-the-router-component) section.
286283

287284
```razor
@@ -292,7 +289,6 @@ When you create a Blazor app from one of the Blazor project templates with authe
292289
DefaultLayout="@typeof(MainLayout)" />
293290
...
294291
</Found>
295-
...
296292
</Router>
297293
</CascadingAuthenticationState>
298294
```
@@ -502,9 +498,6 @@ Not authorized.
502498

503499
To authorize users for resources, pass the request's route data to the <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeRouteView.Resource> parameter of <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeRouteView>.
504500

505-
<!-- UPDATE 8.0 Confirm the following remark in the BWA world
506-
i.e., did Found content survive the NotFound drop? -->
507-
508501
In the <xref:Microsoft.AspNetCore.Components.Routing.Router.Found?displayProperty=nameWithType> content for a requested route:
509502

510503
```razor
@@ -605,9 +598,6 @@ In the following `EditUser` component, the resource at `/users/{id}/edit` has a
605598

606599
The <xref:Microsoft.AspNetCore.Components.Routing.Router> component, in conjunction with the <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeRouteView> component, allows the app to specify custom content if:
607600

608-
<!-- UPDATE 8.0 React to NotFound changes in the BWA world
609-
the following removed NotFound content and tags -->
610-
611601
* The user fails an [`[Authorize]`](xref:Microsoft.AspNetCore.Authorization.AuthorizeAttribute) condition applied to the component. The markup of the [`<NotAuthorized>`](xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeRouteView.NotAuthorized?displayProperty=nameWithType) element is displayed. The [`[Authorize]`](xref:Microsoft.AspNetCore.Authorization.AuthorizeAttribute) attribute is covered in the [`[Authorize]` attribute](#authorize-attribute) section.
612602
* Asynchronous authorization is in progress, which usually means that the process of authenticating the user is in progress. The markup of the [`<Authorizing>`](xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeRouteView.Authorizing?displayProperty=nameWithType) element is displayed.
613603

@@ -624,13 +614,22 @@ The <xref:Microsoft.AspNetCore.Components.Routing.Router> component, in conjunct
624614
</Authorizing>
625615
</AuthorizeRouteView>
626616
</Found>
627-
...
628617
</Router>
629618
</CascadingAuthenticationState>
630619
```
631620

621+
:::moniker range=">= aspnetcore-8.0"
622+
623+
The content of `<NotAuthorized>` and `<Authorizing>` tags can include arbitrary items, such as other interactive components.
624+
625+
:::moniker-end
626+
627+
:::moniker range="< aspnetcore-8.0"
628+
632629
The content of `<NotFound>`, `<NotAuthorized>`, and `<Authorizing>` tags can include arbitrary items, such as other interactive components.
633630

631+
:::moniker-end
632+
634633
If the `<NotAuthorized>` tag isn't specified, the <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeRouteView> uses the following fallback message:
635634

636635
```html

aspnetcore/blazor/security/server/index.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,6 @@ services.AddScoped<AuthenticationStateProvider,
197197

198198
Confirm or add an <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeRouteView> and <xref:Microsoft.AspNetCore.Components.Authorization.CascadingAuthenticationState> for the Blazor router:
199199

200-
<!-- UPDATE 8.0 Check for dropping NotFound
201-
Did Found survive? -->
202-
203200
```razor
204201
<CascadingAuthenticationState>
205202
<Router ...>
@@ -208,7 +205,6 @@ Confirm or add an <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeR
208205
DefaultLayout="@typeof(MainLayout)" />
209206
...
210207
</Found>
211-
...
212208
</Router>
213209
</CascadingAuthenticationState>
214210
```

0 commit comments

Comments
 (0)