In the Visual Studio template for .NET MAUI Blazor Hybrid and web app template with "InteractiveWebAssembly", I get the following projects:
MauiApp1
(Mobile and Windows Clients)MauiApp1.Web
(The host that serves Web.Client)MauiApp1.Web.Client
(The client / WASM)MauiApp1.Shared
(Shared components and interfaces)There is a service interface IFormFactor
defined in the shared project with an implementation in each of the other three projects.
When I start my solution with the web project as the startup project, I can see that the first load of the page used the web implementation of IFormFactor
, and if I navigate away and come back, then I see it using the Web.Client
implementation of IFormFactor
.
I understand that this is due to server pre-rendering.
In my case I only want to use services from the client. How can I avoid that pre-rendering so the first render uses services injected from the client DI, instead of the server DI?
Found the answer.
In my Web project's App.razor file I had:
<HeadOutlet @rendermode="InteractiveWebAssembly" />
<Routes @rendermode="InteractiveWebAssembly" />
This resulted in pre-rendering.
Changing these to:
<HeadOutlet @rendermode="new InteractiveWebAssembly(prerender: false)" />
<Routes @rendermode="new InteractiveWebAssembly(prerender: false)" />
Prevented pre-rendering on the server and my services are injected from client DI on first load of page.