Blazor is all about components. We create different types of components and reuse them throughout the project. Nobody wants to reinvent the wheel so it is always a good idea to create a library of reusable Blazor components that can not only be shared across multiple projects but can also be shared with others as a NuGet package. Blazor allows us to create such component libraries with the help of a new project template called Razor Class Library and in this post, I will show you how to create such a library and share not only components but also static contents such as images, stylesheets, etc.

Table of Contents

  • Creating a Razor Components Library
  • Creating a Component in Razor Class Library
  • Consuming a Razor Component from Razor Class Library
  • Consuming Images from Razor Class Library
  • Consuming Stylesheets from Razor class library
  • Summary

Creating a Razor Components Library

Create a new Blazor Server App with the name BlazorClassLibraryDemo in Visual Studio 2019. Make sure you can build and run your project without any problem. If you are not sure how to create Blazor Server apps then I will recommend you to read my post  A Beginner’s Guide To Blazor Server and WebAssembly Applications

To add a new components library in your Blazor project, right-click on the solution and choose Add > New Project… option. Choose Razor Class Library project template from the list of available project templates

#blazor #components

A Developer’s Guide to Blazor Component Libraries
2.15 GEEK