1

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.razor and MainLayout.razor
  • Move <script src="@Assets["_framework/blazor.web.js"]"></script> into AdminLayout.razor and 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?

3
  • 1
    Do the same as the template does and put @attribute [ExcludeFromInteractiveRouting] within the _Imports.razor file in the same directory as the pages. The template places this in \Components\Account\Pages\_Imports.razor Commented Nov 10 at 19:18
  • @BrianParker Oops! I was trying to add interactivity to a project generated via the Static SSR template. Somehow never actually looked at the App.razor in a project generated via the InteractiveServer .NET 10 template, I had only used .NET 8 previously. Doh, that was a waste of a few hours. Thank you very much, that works Commented Nov 11 at 0:13
  • I have turned this into and answer not just a comment so it gets closed of correctly. Commented Nov 13 at 1:00

1 Answer 1

0

Placing @attribute [ExcludeFromInteractiveRouting] on any page excludes it from interactive routing.

The Blazor templates do this with the Account pages.

The template places this in \Components\Account\Pages\_Imports.razor. This then is included in all pages within that directory.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.