Does anyone know if there's an easy way in Blazor to have:
- A frontend/'user facing' site using Blazor Static SSR I don't want to include blazor.web.js, no enhanced navigation or streaming rendering needed (no interactivity at all except with vanilla JS)
- An admin panel under the /admin/* route that uses InteractiveServer render mode.
It all needs to be hosted by the same process.
I've tried two different ways and can't get this working correctly, each way almost does it but then hits problems.
Attempt 1
- Have a single project, set the render mode as none (i.e. Static SSR)
- Have two layouts
AdminLayout.razorandMainLayout.razor - Move
<script src="@Assets["_framework/blazor.web.js"]"></script>intoAdminLayout.razorand then every component that uses this layout have@rendermode InteractiveServer.
This almost works, you have to ensure you use data-enhance-nav=false while linking from admin -> home otherwise the blazor enhanced nav leaks into it, but it's not a huge problem.
The real problem with this is: AdminLayout.razor can't have InteractiveServer rendermode because it's a layout, and therefore you can't have any InteractiveServer components wrap @body? So for example, one of MudBlazors interactive components in the layout wraps @body I couldn't get it to be interactive. You can supply the rendermode on components not wrapping body but otherwise not?
Attempt 2
Create a second Razor Class Library for the admin pages including its own AdminApp.razor and AdminRoutes.razor. Register both in program.cs:
app.MapRazorComponents<App>(); app.MapRazorComponents<AdminApp>() .AddInteractiveServerRenderMode(); Then you can use InteractiveServer rendermode on both <AdminRoutes and in your admin layout... but now ResourcePreloader and ImportMap don't work because the static assets are built into the main project, not the razor class library.
Attempt 3 (?)
The other test suggested was to host the different blazor in different _Host.cshtml / _AdminHost.cshtml files and do it that way but I couldn't get this working at all. I could get it to host single razor components but not a full blazor 'app'.
This seems like a pretty vanilla use case; blazor static SSR on the user facing pages, blazor InteractiveServer on the admin panel where latency/SEO doesn't matter at all, but I couldn't make it work even after reading all the MS Docs. Any ideas?
@attribute [ExcludeFromInteractiveRouting]within the_Imports.razorfile in the same directory as the pages. The template places this in\Components\Account\Pages\_Imports.razor