I have a folder of components under the Shared directory.
>Shared
+Components
+MyComponentType1
-MyComponentType1Base.razor
-MyComponentType1Title.razor
+MyComponentType2
-MyComponentType2Base.razor
-MyComponentType2Title.razor
-MainLayout.razor
To include all the elements of the components subfolders i have to write all the using statements in the _Imports.razor
@using MyApp.Shared.Components.MyComponentType1
@using MyApp.Shared.Components.MyComponentType2
So my question is: Is there a way to regroup all the components in the subfolders in the Component directory so that i'd use only one using statement?
@using MyApp.Shared.Components
The @namespace
directive was added a few versions back. You can use this to override the default namespace of your components which is the folder path by default.
+MyComponentType1
-MyComponentType1Base.razor
-MyComponentType1Title.razor
+MyComponentType2
-MyComponentType2Base.razor
-MyComponentType2Title.razor
MyComponentType1Title.razor
@namespace MyComponents
<span>Component implementation</span>
MyComponentType2Title.razor
@namespace MyComponents
<span>Component implementation</span>
_Imports.razor
@using MyComponents
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.