I have a working Blazor 7 WASM app . It has the following <Router> code in App.razor file :
<Router AppAssembly="@typeof(Program).Assembly"><Found Context="routeData"><AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"><NotAuthorized><h2>You are not authorized.</h2><h3>To log in click <a href="/Accounts/LogIn">here</a>.</h3></NotAuthorized></AuthorizeRouteView></Found><NotFound><CascadingAuthenticationState><LayoutView Layout="@typeof(MainLayout)"><p>Sorry, there's nothing at this address.</p></LayoutView></CascadingAuthenticationState></NotFound></Router>I moved the same app in Blazor 8 Interactive Web Assembly and added the above code in the Routes.razor component in the Server project (that is, project without .client). But above code doesn't work anymore.
For example, all the app components that have [Authorize] attribute now throw 401 error instead of showing the <NotAuthorized> section above.
Similarly, navigating to a wrong URL doesn't display the <NotFound> section.
This works perfectly as expected in Blazor 7 but not working in Blazor 8. My Blazor 8 Routes.razor is given below :
<Router AppAssembly="@typeof(Program).Assembly" AdditionalAssemblies="new[] { typeof(Client._Imports).Assembly }"><Found Context="routeData"><AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"><NotAuthorized><h2>You are not authorized.</h2><h3>To log in click <a href="/Accounts/LogIn">here</a>.</h3></NotAuthorized></AuthorizeRouteView></Found><NotFound><CascadingAuthenticationState><LayoutView Layout="@typeof(MainLayout)"><p>Sorry, there's nothing at this address.</p></LayoutView></CascadingAuthenticationState></NotFound></Router>I also tried wrapping the whole <Router> inside <CascadingAuthenticationState> but still problem persists.
What might be the problem? Where do I need to fix?
Please help.