Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering Menu Module in Blazor WASM at Runtime #271

Open
shahabfar opened this issue May 1, 2024 · 1 comment
Open

Rendering Menu Module in Blazor WASM at Runtime #271

shahabfar opened this issue May 1, 2024 · 1 comment

Comments

@shahabfar
Copy link

I am currently working on a project using the ABP Framework with a Blazor front end, and I’ve encountered a challenge that I’m hoping you might be able to assist me with.

I am trying to update the main menu items dynamically, but unfortunately, the changes are not being rendered as expected.
I injected IMenuManager into my blazor page and use the following code to update my menu (Test submenu items in my case).

    var mainMenu = await MenuManager.GetMainMenuAsync();
    var testMenu = mainMenu.FindMenuItem("Test");

    // Clear the existing menu items
    testMenu.Items.Clear();

    // Add the new menu items
    foreach (var item in MyItems)
    {
        testMenu.AddItem(
            new ApplicationMenuItem(
                $"Test.{item.Name}",
                item.Name,
                url: $"/test/{item.Id}"
            )
        );
    }

When I call the above method, the main menu does not reflect the updates. I suspect that I need to invoke StateHasChanged() on the ABP menu module (component), but I’m unsure how to access it.

I’ve searched through the ABP documentation and community forums, but I haven’t been able to find a solution to this issue.
Is there any workaround for this?
Thanks.

@maliming
Copy link
Member

maliming commented May 2, 2024

hi

You can try to override the IMenuManager service to maintain the menus.

The menu's component will refresh the menu on the Changed event of ApplicationConfigurationChangedService.

https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/MenuManager.cs#L14
https://github.com/abpframework/abp/blob/dev/modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/Themes/Basic/NavMenu.razor.cs#L24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants