Commit d8a48c6f authored by ToiWright's avatar ToiWright Committed by Daniel Roth
Browse files

Update 01-components-and-layout.md

parent 8d2033fc
......@@ -55,7 +55,7 @@ To get the available list of specials we need to call an API on the backend. Bla
@inject HttpClient HttpClient
```
The `@inject` directive essentially defines a new property on the component where the first token specified the property type and the second token specifies the property name. The property is populated for you using dependency injection.
The `@inject` directive essentially defines a new property on the component where the first token specifies the property type and the second token specifies the property name. The property is populated for you using dependency injection.
Override the `OnInitializedAsync` method in the `@code` block to retrieve the list of pizza specials. This method is part of the component lifecycle and is called when the component is initialized. Use the `GetFromJsonAsync<T>()` method to handle deserializing the response JSON:
......@@ -94,14 +94,14 @@ Once the component is initialized it will render its markup. Replace the markup
</div>
```
Run the app by hitting `Ctrl-F5`. Now you should see a list of the specials available.
Run the app by hitting `Ctrl-F5`. Now you should see a list of the specials that are available.
![image](https://user-images.githubusercontent.com/1874516/77239386-6c558880-6b97-11ea-9a14-83933146ba68.png)
## Create the layout
Next we'll set up the layout for app.
Next we'll set up the layout for the app.
Layouts in Blazor are also components. They inherit from `LayoutComponentBase`, which defines a `Body` property that can be used to specify where the body of the layout should be rendered. The layout component for our pizza store app is defined in *Shared/MainLayout.razor*.
......@@ -113,9 +113,9 @@ Layouts in Blazor are also components. They inherit from `LayoutComponentBase`,
</div>
```
To see how the layout is associated with your pages, look at the `<Router>` component in `App.razor`. Notice the `DefaultLayout` parameter which determines the layout used for any page that doesn't specify its own layout directly.
To see how the layout is associated with your pages, look at the `<Router>` component in `App.razor`. Notice that the `DefaultLayout` parameter determines the layout used for any page that doesn't specify its own layout directly.
You can also override this `DefaultLayout` on a per-page basis. To do so, you can add directive such as `@layout SomeOtherLayout` at the top of any `.razor` page component. However, you don't need to do so in this application.
You can also override this `DefaultLayout` on a per-page basis. To do so, you can add a directive such as `@layout SomeOtherLayout` at the top of any `.razor` page component. However, you will not need to do so in this application.
Update the `MainLayout` component to define a top bar with a branding logo and a nav link for the home page:
......@@ -136,11 +136,11 @@ Update the `MainLayout` component to define a top bar with a branding logo and a
</div>
```
The `NavLink` component is provided by Blazor. Components can be used from components, which is done by specifying an element with the component's type name along with attributes for any component parameters.
The `NavLink` component is provided by Blazor. Components can be used from components by specifying an element with the component's type name along with attributes for any component parameters.
The `NavLink` component is the same as an anchor tag, except that it adds an `active` class if the current URL matches the link address. `NavLinkMatch.All` means that the link should be active only when it matches the entire current URL (not just a prefix). We'll examine the `NavLink` component in more detail in a later session.
Run the app by hitting `Ctrl-F5`. With our new layout our pizza store app now looks like this:
Run the app by hitting `Ctrl-F5`. With our new layout, our pizza store app now looks like this:
![image](https://user-images.githubusercontent.com/1874516/77239419-aa52ac80-6b97-11ea-84ae-f880db776f5c.png)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment