Building Single Page Applications in .NET Core 3 by Michele Aponte

Building Single Page Applications in .NET Core 3 by Michele Aponte

Author:Michele Aponte
Language: eng
Format: epub
ISBN: 9781484257470
Publisher: Apress


Listing 3-8The Code That Manages the Main Menu Component in the App Component

Note the method MenuItemClick(), called when the OnMenuItemClick custom event is raised: the code sets the Active property of the MenuItems array to false and also sets the Active property of the item clicked to true. The change detection of Blazor notes this change and updates the user interface, setting the active class on the item clicked. The fascinating aspect is the way it executes the update: Blazor knows the state of the user interface, so when the code wants to change it, the framework computes the difference between the actual state and the new state and applies the difference only to the DOM of the browser. This technique, also used by many JavaScript frameworks, speeds up the update of the user interface significantly.

In Figure 3-5, you can see the result of our work. Using the OnMenuItemClick event , we can show or hide other components, simulating the page navigation. By doing it this way, besides being too laborious, we would also miss out on advanced navigation features, which we can get for free by using the routing features made available by the framework.

Figure 3-5The main menu component in action



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.