Blazor client-side routing migration (#20809)
parent
f8903603c3
commit
de386f1499
|
@ -4,7 +4,7 @@ author: scottaddie
|
|||
description: Learn how to migrate an ASP.NET Core 3.1 project to ASP.NET Core 5.0.
|
||||
ms.author: scaddie
|
||||
ms.custom: mvc
|
||||
ms.date: 11/24/2020
|
||||
ms.date: 11/30/2020
|
||||
no-loc: [appsettings.json, "ASP.NET Core Identity", cookie, Cookie, Blazor, "Blazor Server", "Blazor WebAssembly", "Identity", "Let's Encrypt", Razor, SignalR]
|
||||
uid: migration/31-to-50
|
||||
---
|
||||
|
@ -58,6 +58,39 @@ If updating a Blazor WebAssembly project, skip to the [Update Blazor WebAssembly
|
|||
</Project>
|
||||
```
|
||||
|
||||
## Changes to Blazor app routing logic in 5.0.1
|
||||
|
||||
The computation of route precedence changed in the ASP.NET Core 5.0.1 patch release. This might affect you if you've defined catch-all routes or routes with optional parameters.
|
||||
|
||||
### Old behavior
|
||||
|
||||
With the prior behavior in ASP.NET Core 5.0.0 or earlier, routes with lower precedence, such as `{*slug}`, are matched before routes with higher precedence, such as `/customer/{id}`.
|
||||
|
||||
### New behavior
|
||||
|
||||
The new behavior in ASP.NET Core 5.0.1 or later more closely matches the routing behavior defined in ASP.NET Core apps, where the framework computes and establishes the route precedence for each segment first and only uses the length of the route to break ties as a secondary criteria.
|
||||
|
||||
### Reason for change
|
||||
|
||||
The original behavior is considered a bug in the implementation because our goal is for the Blazor routing system to behave in the same way as the ASP.NET Core routing system for the subset of features supported by Blazor routing.
|
||||
|
||||
### Recommended action
|
||||
|
||||
Add the `PreferExactMatches` attribute to the `Router` component in the `App.razor` file to opt into the correct behavior:
|
||||
|
||||
```razor
|
||||
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="true">
|
||||
```
|
||||
|
||||
When `PreferExactMatches` is set to `true`, route matching prefers exact matches over wildcards.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> All apps should explicitly set `PreferExactMatches` to `true`.
|
||||
>
|
||||
> The ability to set the option to `false` or leave it unset, which defaults the option to `false`, *is only provided for backward compatibility*.
|
||||
>
|
||||
> When .NET 6 is released, the router will always prefer exact matches, and the `PreferExactMatches` option won't be available.
|
||||
|
||||
## Update Blazor WebAssembly and Blazor Server projects
|
||||
|
||||
*The guidance in this section applies to both Blazor hosting models. Sections following this section provide additional guidance specific to hosting models and app types. Apply the guidance from all relevant sections to your app.*
|
||||
|
|
Loading…
Reference in New Issue