Component lifecycles

Blazor components have a number of virtual methods we can override to affect the behaviour of our application. These methods are executed at different times during a component’s lifetime. The following diagram outlines the flow of these lifecycle methods. Component lifecycle diagram SetParametersAsync This method is executed whenever the parent renders. Parameters that were passed […]

Passing HTML element references

When writing a Blazor application, manipulation of the Document Object Model (DOM) is discouraged as it may interfere with its incremental render tree, any changes to HTML should be managed in .NET code inside our components. Sometimes we may wish to proceed anyway and let JavaScript interact with our generated HTML. The standard JavaScript method […]

Navigating our app via HTML

The simplest way to link to a route within a Blazor component is to use an HTML hyperlink. Hyperlinks in a Blazor component are intercepted automatically. When a user clicks a hyperlink the browser will not send a request to the server, instead Blazor will update the URL in the browser and render whichever page […]

Route parameters

So far we’ve seen how to link a static URL to a Blazor component. Static URLs are only useful for static content, if we want the same component to render different views based on information in the URL (such as a customer ID) then we need to use route parameters. A route parameter is defined […]

Routing

As with a standard ASP.NET MVC, Blazor routing is a technique for inspecting the browser’s URL and matching it up to a page to render. Routing is more flexible than simply matching a URL to a page. It allows us to match based on patterns of text so that, for example, both URLs in the […]