Reputation: 32966
I want to make sure I understand how Blazor (server side) builds up a web page. Is the following correct?
Is the above correct? And can someone answer the five questions above?
Upvotes: 0
Views: 686
Reputation: 30167
_Host.cshtml
is a standard server side web page rendered on the server. What brings Blazor to life is: <script src="_framework/blazor.server.js"></script>
This runs the client side Blazor Server scripts, establishes a SignalR
connection with the server and replaces the content is any Component
tags with content provided by the Blazor Hub session Renderer. The type defined in each component becomes the root component of a component tree that the Renderer (in the Blazor Server hub session) maintains. It passes changes to this render tree to the client side code to apply to the rendered DOM.
blazor.server.js
starts when the browser loads the page and establishes a SignalR
session with the server and requests the components. From that point it listens for updates on the SignalR
session and applies them to the browser DOM.
MainLayout
is just another component, designed to be a Layout: just part of the Render Tree. It's the ChildContent of AuthorizeRouteView
which is the ChildContent
of the Router
component. It gets rendered whenever the supplied component in RouteData
changes.
AuthorizeRouteView
is the component that controls Authorization. It gets it's authentication data from CascadingAuthenticationState
.
_ValidationScriptsPartial
is just part of the server side authentication code. Most of the code is template code provided by the authentication library and not visible in the project.For example the Register Page:
<a class="nav-link text-dark" asp-area="Identity" asp-page="/Account/Register">Register</a>
For more information on components there's an article here: https://www.codeproject.com/Articles/5277618/A-Dive-into-Blazor-Components
Upvotes: 1
Reputation: 273464
A slightly better starting point would be the "Blazor Server App Empty" template. The NavMenu component is just that, a Component.
8.5 As this all starts with _Host.cshtml, it appears that Blazor is built on top of MVC
Close. _Host.cshtml
is a Razor Page. And <component type="typeof(App)" >
is a "Razor Component" aka Blazor.
A Blazor Server app is in fact a Razor Pages app running one big component. You can use everything available in Razor Pages around your Blazor app, but not inside it.
And your program starts of course in Program.cs
, and the line app.MapFallbackToPage("/_Host");
fires it all up.
Upvotes: 1