How do I get Blazor Server and Blazor WebAssembly to run side-by side so I may utilise the new features of .Net8?
I have an .Net8 core applicaton utilising client-side rendering (CSR) using Blazor WebAssembly. It’s a none-trivial application using services instantiated by the client (for authentication, uistate, local storage etc)
I would like to implement a handful of server-side rendered pages. (Login pages, and redirection) that do not require the full WebAssembly to load.
The WebAssembly client works, as per MS docs:
<Routes @rendermode="new InteractiveWebAssemblyRenderMode(prerender: false)" />
and
<Router AppAssembly="@typeof(Client.Program).Assembly">
To get server side rendering to work, I can implement
<Routes />
and
<Router AppAssembly="@typeof(Sever.Program).Assembly">
With this configuration, I can render pages server-side, and even render some (trivial) WebAssembly components. However, when doing so, the WebAssembly entry point is no longer invoked (ie WebAssembly.Program() is not executed) and the WebAssembly client is not set up to run correctly. I end up with server errors decribing a failure to instantiate client only objects (ie localStorage) for the substantial part.
How do I get Blazor Server and Blazor WebAssembly to run side-by side so I may utilise the new features of .Net8?
I expect (hope!) the answer lies in one (or all) of the following
- modification of
<Routes
such that certain urls reference a different AppAssembly (?!) - modification of
endpoints.MapRazorComponents<App>()
to identify between WebAssembly parts from Server parts - anything else!(!?)
With many thanks in advance.