How to use subfolders in the Pages and Shared fold

2020-07-18 08:35发布

问题:

I've got a Blazor Server-Side application. It has the folders Pages and Shared out-of-the-box. Since I have a lot of components in these folders, I wanted to distribute the components into multiple subfolders for a clearer structure. But if I do this, the components are not found and are not displayed in the GUI. What am I missing? Do I have to register the routes to the new subfolders somewhere?

回答1:

You can have whatever folder structure you wish. But you will need to update your _Imports.razor with the new namespaces.

For example if you have a structure of

MyProject/Components/Forms/MyInput.razor

You would need the following in your _Imports.razor:

@using MyProject.Components.Forms;

The other option is to reference components using their fully qualified namespace:

<MyProject.Components.Forms.MyInput/>