yes. the default is static and the components can override the default. a running Blazor app only support one interactive mode (client or server). switching modes (like client to server, or prerender to interactive), unloads a Blazor instance and starts a new instance.
Can I use global interactivity along with per page interactivity in same project of .net 8 blazor web app ?
I have created a blazor web app application and I want to use global auto render mode along with per page interactivity mode in same project, is it possible ?
2 answers
Sort by: Most helpful
-
-
Jerry Fu - MSFT 571 Reputation points Microsoft Vendor
2024-05-29T01:50:26.8566667+00:00 Hi, @Kuldeep Y
Sure, you could use global dynamic rendermode in App.razor for this purpose. Try modify App.razor like following :
... <HeadOutlet @rendermode="RenderModeForPage()" /> ... <Routes @rendermode="RenderModeForPage()" /> ... @code { [CascadingParameter] private HttpContext HttpContext { get; set; } = default!; //if the page route is "/Counter" ,the rendermode is set to null, equals to SSR private IComponentRenderMode? RenderModeForPage(){ if (HttpContext.Request.Path.StartsWithSegments("/Counter")) { return null; } else { return InteractiveAuto; } } }
Then the "counter" button will be ineffective because we dynamically set it to static mode. But you could then add rendermode to the Counter page, the button will work again with "InteractiveServer"
@page "/counter" @rendermode InteractiveServer ...
You could also reference this document https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-8.0#set-the-render-mode-by-component-instance
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.