Menu Builder Feature¶
Basic Usage¶
The minimum requirements are as follows:
- Create a class with the
[BlazorPath]
attribute. The class definition must include thepartial
attribute. - Define constants of type
const string
as members within the class. - Add the
[Item("DisplayName")]
attribute to the members.
BlazorPathHelper will automatically scan for class definitions that meet these criteria and generate menu structure data.
WebPaths.cs | |
---|---|
1 2 3 4 5 6 7 8 |
|
Generated Code
Auto Generated Code | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Adding Submenus¶
If the URLs have a hierarchical structure, submenus will be generated automatically.
For example, consider a menu with the following hierarchical structure:
Text Only | |
---|---|
1 2 3 4 5 6 7 8 |
|
In this case, you would define the class as follows. No special processing is required.
WebPaths.cs | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Generated Code (Excerpt)
Auto Generated Code | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
The generated child elements are stored in the Children
property.
Displaying the Menu¶
In the simplest example, the structure would look like this:
NavMenu.razor | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Of course, you can modify the design to suit each component. For more details, refer to Framework Examples.
Customizing Menu Items¶
Refer to Customizing Menu Items.
Details of Generated Properties¶
The following properties are generated as part of the BlazorPathMenuItem
class. For more details, refer to BlazorPathMenuItem and ItemAttribute.
Property of BlazorPathMenuItem |
Specification Method for ItemAttribute |
Description | Default Value |
---|---|---|---|
Key | (Auto-generated) | A unique key (string) for the entire menu | — |
Index | (Auto-generated) | An index (number) for the entire menu | — |
GroupKey | Group |
A string representing the menu's hierarchy. Items with the same GroupKey belong to the same group. | Automatically determined from URL (e.g., /foo/bar becomes /foo ) |
GroupLevel | (Auto-generated) | The hierarchy level of the menu. The top level is 0. | — |
GroupIndex | (Auto-generated) | An index (number) within the submenu | — |
Path | (Auto-generated) | The link destination of the menu | Value of the const string variable |
Name | Name or first argument |
The display name of the menu. Can support i18n by specifying a resource key name. | Variable name |
Description | Description |
A description of the menu | NULL |
Icon | Icon or specified generically (for classes) |
The icon of the menu | NULL |
Children | (Auto-generated) | The child elements of the menu | Empty array |