.NET 8 - Blazor Server with Per page/component interactivity vs Global
What's the difference? I don't understand the documentation.
10 Replies
Per page defines how that component/page works. Global is a universal default if a page/component does not specify
Basically just rules of specificity
[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;
private IComponentRenderMode? RenderModeForPage => HttpContext.Request.Path.StartsWithSegments("/Account")
? null
: InteractiveServer;
when i created a Blazor Server app with Global, i noticed this in App.razor. Why is it here?
<HeadOutlet @rendermode="RenderModeForPage" />
<Routes @rendermode="RenderModeForPage" />
it's used in both of these
ig my question from that would be, why would I ever use per-page if i'm using Server or WASM exclusively? Wouldn't per-page only be useful if i'm using Interactive Auto
if you're using exclusively a single render mode, I would assume you wouldn't want per page/component. I would remove that. In the example above it seems that the page is just cascading the render mode down, since the components may specify a different default mode.
gotcha, that's what i assumed. I forgot to add that this most likely was part of the template I chose bc I selected to add Auth with individual accounts?
Is that even needed since its all Interactive Server
Probably. The templates were recently updated, so they may be less succinct to show off new capabilities
I think it depends on
HeadOutlet
and Routes
default render mode. They may have a @rendermode
directive in the component that specifies something different
I'd have to look though<HeadOutlet @rendermode="InteractiveServer" />
<Routes @rendermode="InteractiveServer" />
would just directly changing it to this be bad practice?
Not if that's what you always want
Or you could remove that, and specify
@rendermode
in the two components
If that's what you want by default, that's what I would dowell i mean for /Accounts it sets rendermode to null currently, yes? how does that affect those components
null would mean that the component rendermode would be checked. If it doesn't set one, then the global will be used
so then its completely fine to just remove it as long as all i want is Interactive Server globally