Exploring Custom Elements
To bring Blazor into an existing Angular or React site, we use a feature called CustomElements
. It was introduced as an experimental feature in .NET 6 and is now part of the framework in .NET 7.
The idea is to create parts of your site in Blazor without having to migrate fully over to Blazor.
For this feature to work, we need to have an ASP.NET backend or manually make sure the _framework
files are available. This is so that we can serve the Blazor framework files.
There are two ways of running CustomElements; we can run it as Blazor WebAssembly or as the Blazor Server. Since we are adding Blazor to a client framework like React or Angular, the most relevant method is to run it as Blazor WebAssembly. Therefore, the samples in these first sections will be for Blazor WebAssembly.
In the GitHub repo, there is a folder called CustomElements
in which you will find the code for the projects, from which we will see sample code in this chapter.