Skip to content

Commit 10cd976

Browse files
authored
Improvements to JS-SPA frameworks article (#36461)
1 parent c3dd63f commit 10cd976

1 file changed

Lines changed: 30 additions & 17 deletions

File tree

aspnetcore/blazor/components/js-spa-frameworks.md

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,27 @@ This article covers how to render Razor components from JavaScript, use Blazor c
2020
<!-- UPDATE 11.0 - The `blazor.web.js` (Blazor Web App) portions of
2121
this article have been commented out for the time being to
2222
facilitate reconstituting the guidance later when support lands.
23-
It was under consideration for .NET 10 on
24-
https://github.com/dotnet/AspNetCore.Docs/issues/35653, but
25-
it didn't make the cut and was backlogged. -->
23+
The PU work is tracked by https://github.com/dotnet/aspnetcore/issues/53920. -->
2624

2725
## Angular sample apps
2826

29-
<!-- UPDATE 10.0 Add migration instructions for 9.0 to 10.0 -->
27+
The following sample apps demonstrate rendering a Razor component as a [Blazor custom element](#blazor-custom-elements) in an Angular app:
3028

31-
* [CustomElementsBlazorSample (Blazor Server) (`javiercn/CustomElementsBlazorSample`, branch: `blazor-server`)](https://github.com/javiercn/CustomElementsBlazorSample/tree/blazor-server): Blazor Server is supported in .NET 8/9. To migrate this .NET 7 sample, see <xref:migration/70-to-80#update-a-blazor-server-app> and <xref:migration/80-to-90>.
32-
* [CustomElementsBlazorSample (Blazor WebAssembly) (`javiercn/CustomElementsBlazorSample`, branch: `blazor-wasm`)](https://github.com/javiercn/CustomElementsBlazorSample/tree/blazor-wasm): To migrate this .NET 7 sample, see <xref:migration/70-to-80#update-a-blazor-webassembly-app> and <xref:migration/80-to-90>.
29+
* [CustomElementsBlazorSample (Blazor Server) (`javiercn/CustomElementsBlazorSample` GitHub repository, branch: `blazor-server`)](https://github.com/javiercn/CustomElementsBlazorSample/tree/blazor-server)
30+
* [CustomElementsBlazorSample (Blazor WebAssembly) (`javiercn/CustomElementsBlazorSample` GitHub repository, branch: `blazor-wasm`)](https://github.com/javiercn/CustomElementsBlazorSample/tree/blazor-wasm)
31+
32+
To migrate either of these .NET 7 samples, see the following resources:
33+
34+
* <xref:migration/70-to-80>
35+
* <xref:migration/80-to-90>
36+
* <xref:migration/90-to-100>
37+
38+
The principal updates to make are:
39+
40+
* Update the [target framework monikers (TFMs)](/dotnet/standard/frameworks) to the latest version.
41+
* Update the .NET package references and Angular dependencies to their latest versions.
42+
43+
[!INCLUDE[](~/includes/package-reference.md)]
3344

3445
## Render Razor components from JavaScript
3546

@@ -340,24 +351,22 @@ builder.Services.AddServerSideBlazor(options =>
340351

341352
### Blazor WebAssembly registration
342353

343-
Take the following steps to register a root component as a custom element in a Blazor WebAssembly app.
344-
345-
Add the <xref:Microsoft.AspNetCore.Components.Web?displayProperty=fullName> namespace to the top of the `Program` file:
346-
347-
```csharp
348-
using Microsoft.AspNetCore.Components.Web;
349-
```
354+
Register a root component as a custom element in a Blazor WebAssembly app. In the following example, the code:
350355

351-
Add a namespace for the app's components. In the following example, the app's namespace is `BlazorSample` and the components are located in the `Pages` folder:
356+
* Adds a namespace for the app's components. In the example, the app's namespace is `BlazorSample`, and the components are located in the `Pages` folder.
357+
* Provides access to the API in the <xref:Microsoft.AspNetCore.Components.Web?displayProperty=fullName> namespace.
358+
* Calls <xref:Microsoft.AspNetCore.Components.Web.CustomElementsJSComponentConfigurationExtensions.RegisterCustomElement%2A> on <xref:Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder.RootComponents> to register the `Counter` component with the custom HTML element `my-counter`.
352359

353360
```csharp
354361
using BlazorSample.Pages;
355-
```
362+
using Microsoft.AspNetCore.Components.Web;
363+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
356364

357-
Call <xref:Microsoft.AspNetCore.Components.Web.CustomElementsJSComponentConfigurationExtensions.RegisterCustomElement%2A> on <xref:Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder.RootComponents>. The following example registers the `Counter` component with the custom HTML element `my-counter`:
365+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
358366

359-
```csharp
360367
builder.RootComponents.RegisterCustomElement<Counter>("my-counter");
368+
369+
await builder.Build().RunAsync();
361370
```
362371

363372
### Use the registered custom element
@@ -475,3 +484,7 @@ Generate JavaScript (JS) components from Razor components for JavaScript technol
475484

476485
> [!WARNING]
477486
> The Angular and React component features are currently **experimental, unsupported, and subject to change or be removed at any time**. We welcome your feedback on how well this particular approach meets your requirements.
487+
488+
## Additional resources
489+
490+
<xref:blazor/host-and-deploy/index>

0 commit comments

Comments
 (0)