Unplanned
Last Updated: 15 Jun 2021 14:25 by ADMIN
Georgia
Created on: 15 Jun 2021 14:25
Category: Menu
Type: Feature Request
8
Expose forceLoad parameter in Menu

The Menu uses the NavigationManager to go to the pages that are assigned to the individual MenuItem objects. Is there a way to pass the "force load" value to these menu items?

 

-------------------- ADMIN EDIT -------------------- 

You can work around the issue if you skip setting Url field of the items that you want to force load and set your own property. Then, handle OnClick of the menu items and check if this property is set and manually call the navigation manager for the URL. You can see the code for this approach below:

public List<MenuItem> MenuItems { get; set; }

protected void OnClickHandler(MenuItem item)
{
    if (item.ForceLoadUrl != null)
    {
        navManager.NavigateTo(item.ForceLoadUrl, true);
    }
}

public class MenuItem
{
    public string Text { get; set; }
    public string Url { get; set; }
    public string ForceLoadUrl { get; set; }
    public List<MenuItem> Items { get; set; }
}

protected override void OnInitialized()
{
    MenuItems = new List<MenuItem>()
    {
        new MenuItem()
        {
            Text = "site.css",
            ForceLoadUrl = "/css/site.css"
        },
        new MenuItem()
        {
            Text = "Counter",
            Url = "/counter"
        },
        new MenuItem()
        {
            Text = "Fetch Data",
            Url = "/fetchdata"
        }
    };

    base.OnInitialized();
}

0 comments