Skip to content

Commit 67231ba

Browse files
authored
Enhance layout+content for component integration (#17793)
1 parent 37e9c3a commit 67231ba

1 file changed

Lines changed: 38 additions & 18 deletions

File tree

aspnetcore/blazor/integrate-components.md

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn about data binding scenarios for components and DOM elements
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 04/01/2020
8+
ms.date: 04/14/2020
99
no-loc: [Blazor, SignalR]
1010
uid: blazor/integrate-components
1111
---
@@ -15,7 +15,14 @@ By [Luke Latham](https://github.com/guardrex) and [Daniel Roth](https://github.c
1515

1616
Razor components can be integrated into Razor Pages and MVC apps. When the page or view is rendered, components can be prerendered at the same time.
1717

18-
## Prepare the app to use components in pages and views
18+
After [preparing the app](#prepare-the-app), use the guidance in the following sections depending on the app's requirements:
19+
20+
* Routable components – For components that are directly routable from user requests. Follow this guidance when visitors should be able to make an HTTP request in their browser for a component with an [`@page`](xref:mvc/views/razor#page) directive.
21+
* [Use routable components in a Razor Pages app](#use-routable-components-in-a-razor-pages-app)
22+
* [Use routable components in an MVC app](#use-routable-components-in-an-mvc-app)
23+
* [Render components from a page or view](#render-components-from-a-page-or-view) – For components that aren't directly routable from user requests. Follow this guidance when the app embeds components into existing pages and views with the [Component Tag Helper](xref:mvc/views/tag-helpers/builtin-th/component-tag-helper).
24+
25+
## Prepare the app
1926

2027
An existing Razor Pages or MVC app can integrate Razor components into pages and views:
2128

@@ -72,7 +79,7 @@ An existing Razor Pages or MVC app can integrate Razor components into pages and
7279

7380
To support routable Razor components in Razor Pages apps:
7481

75-
1. Follow the guidance in the [Prepare the app to use components in pages and views](#prepare-the-app-to-use-components-in-pages-and-views) section.
82+
1. Follow the guidance in the [Prepare the app](#prepare-the-app) section.
7683

7784
1. Add an *App.razor* file to the project root with the following content:
7885

@@ -139,15 +146,15 @@ To support routable Razor components in Razor Pages apps:
139146
...
140147
```
141148

142-
For more information on namespaces, see the [Component namespaces](#component-namespaces) section.
149+
For more information on namespaces, see the [Component namespaces](#component-namespaces) section.
143150

144151
## Use routable components in an MVC app
145152

146153
*This section pertains to adding components that are directly routable from user requests.*
147154

148155
To support routable Razor components in MVC apps:
149156

150-
1. Follow the guidance in the [Prepare the app to use components in pages and views](#prepare-the-app-to-use-components-in-pages-and-views) section.
157+
1. Follow the guidance in the [Prepare the app](#prepare-the-app) section.
151158

152159
1. Add an *App.razor* file to the root of the project with the following content:
153160

@@ -178,6 +185,19 @@ To support routable Razor components in MVC apps:
178185
```
179186

180187
Components use the shared *_Layout.cshtml* file for their layout.
188+
189+
<xref:Microsoft.AspNetCore.Mvc.Rendering.RenderMode> configures whether the `App` component:
190+
191+
* Is prerendered into the page.
192+
* Is rendered as static HTML on the page or if it includes the necessary information to bootstrap a Blazor app from the user agent.
193+
194+
| Render Mode | Description |
195+
| ----------- | ----------- |
196+
| <xref:Microsoft.AspNetCore.Mvc.Rendering.RenderMode.ServerPrerendered> | Renders the `App` component into static HTML and includes a marker for a Blazor Server app. When the user-agent starts, this marker is used to bootstrap a Blazor app. |
197+
| <xref:Microsoft.AspNetCore.Mvc.Rendering.RenderMode.Server> | Renders a marker for a Blazor Server app. Output from the `App` component isn't included. When the user-agent starts, this marker is used to bootstrap a Blazor app. |
198+
| <xref:Microsoft.AspNetCore.Mvc.Rendering.RenderMode.Static> | Renders the `App` component into static HTML. |
199+
200+
For more information on the Component Tag Helper, see <xref:mvc/views/tag-helpers/builtin-th/component-tag-helper>.
181201

182202
1. Add an action to the Home controller:
183203

@@ -209,7 +229,19 @@ To support routable Razor components in MVC apps:
209229
...
210230
```
211231

212-
For more information on namespaces, see the [Component namespaces](#component-namespaces) section.
232+
For more information on namespaces, see the [Component namespaces](#component-namespaces) section.
233+
234+
## Render components from a page or view
235+
236+
*This section pertains to adding components to pages or views, where the components aren't directly routable from user requests.*
237+
238+
To render a component from a page or view, use the [Component Tag Helper](xref:mvc/views/tag-helpers/builtin-th/component-tag-helper).
239+
240+
For more information on how components are rendered, component state, and the `Component` Tag Helper, see the following articles:
241+
242+
* <xref:blazor/hosting-models>
243+
* <xref:blazor/hosting-model-configuration>
244+
* <xref:mvc/views/tag-helpers/builtin-th/component-tag-helper>
213245

214246
## Component namespaces
215247

@@ -225,15 +257,3 @@ When using a custom folder to hold the app's components, add the namespace repre
225257
The *_ViewImports.cshtml* file is located in the *Pages* folder of a Razor Pages app or the *Views* folder of an MVC app.
226258

227259
For more information, see <xref:blazor/components#import-components>.
228-
229-
## Render components from a page or view
230-
231-
*This section pertains to adding components to pages or views, where the components aren't directly routable from user requests.*
232-
233-
To render a component from a page or view, use the [Component Tag Helper](xref:mvc/views/tag-helpers/builtin-th/component-tag-helper).
234-
235-
For more information on how components are rendered, component state, and the `Component` Tag Helper, see the following articles:
236-
237-
* <xref:blazor/hosting-models>
238-
* <xref:blazor/hosting-model-configuration>
239-
* <xref:mvc/views/tag-helpers/builtin-th/component-tag-helper>

0 commit comments

Comments
 (0)