dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
34.9k stars 9.86k forks source link

Should forceReload cause a full navigation when using the NavigationManager and SSR? #49651

Open danroth27 opened 12 months ago

danroth27 commented 12 months ago

NavigationManager.NavigateTo(...) has a forceReload parameter that is used in interactive rendering to force a full-page navigation instead of using client-side routing. Should this parameter also force a full-page navigation when using server-side rendering and enhanced navigation?

cschulzsuper commented 11 months ago

I think I can add to that. I was playing around with SSR, and came to the point where I wanted to navigate to the swagger\index.html. Swagger is hosted in the same project. The navigation happens in the submit handler of an EditForm. The problem is that the navigation happens, but the browser shows only a blank page. I need to manually refresh to load Swagger.

Since Swagger is not part of SSR, I thought it would be better to give it fresh start by doing a forceReload. Sadly, that parameter is currently ignored.

I'm unsure if it is a bug that swagger is not showing when forceReload is set to false, but true should definitely work.

MackinnonBuck commented 10 months ago

The forceLoad parameter is already respected when NavigationManager.NavigateTo() is called from an interactive component and server-side routing is in use.

However, NavigateTo() can also be used to trigger a redirect from a component while performing an SSR. In that case, the forceLoad parameter is completely ignored. Let's use this issue to track the case where NavigateTo is called during server-side rendering.

We might be able to fix this by adding an extra property to NavigationException (e.g., ForceLoad) and add the "blazor-enhanced-nav-redirect-location" header to the response if that property is true. This should cause the client to abort the enhanced navigation and perform a full page load.

andoband commented 5 months ago

I have an app built with Blazor WebAssembly. I'm exploring converting some/most/all to Blazor SSR with enhanced nav/forms. I'm starting with converting our sign in page to SSR. It uses enhanced form submission posting username and password and if the authentication is successful, I'd like to redirect to the app's home page. My initial instinct was to use NaviationManager.NavigateTo(forceLoad:true). It doesn't work though. I see a 302 is returned, but fetch is used to load the redirect, and consequently the browser isn't redirected. I guess I'll have to do some JS interop to accomplish what I want. It would be nice to have the Blazor JS do the redirect in response to a NavigateTo().