New to Telerik UI for Blazor? Download free 30-day trial

Drawer for Navigation

The Drawer is a different kind of a menu that is commonly used to navigate between pages in the app - it can generate the needed links for you through its UrlField when data binding.

To use the Drawer for navigating between pages:

  • Add the Drawer to the MainLayot.razor of your app.
  • Put the @Body tag in the <Content> tag of the drawer.
  • Provide a collection of models that describe the pages you want the user to navigate to.

You can find a runnable sample that showcases this in the Drawer as Side Navigation sample project.

Use the Drawer for Navigation in MainLayout.razor

@* This is a very basic layout to showcase the concept. You may want to add a header, footer, 
    collapse/expand button and add desired heights to the layout and drawer *@

@inherits LayoutComponentBase

<TelerikRootComponent>

    <TelerikDrawer Data="@NavigablePages" Expanded="true" MiniMode="true" Mode="@DrawerMode.Push">
        <Content>
            @Body
        </Content>
    </TelerikDrawer>

</TelerikRootComponent>

@code{ 
    List<DrawerItem> NavigablePages { get; set; } =
        new List<DrawerItem>
        {
            new DrawerItem { Text = "Home", Url = "/", Icon = "home" },
            new DrawerItem { IsSeparator = true },
            new DrawerItem { Text = "Counter", Url = "counter", Icon = "plus-outline" },
            new DrawerItem { Text = "FetchData", Url = "fetchdata", Icon = "grid" }
        };

    public class DrawerItem
    {
        public string Text { get; set; }
        public string Url { get; set; }
        public string Icon { get; set; }
        public bool IsSeparator { get; set; }
    }
}

Notes

  • The UrlField has a default value (Url) and that will be used if present in the model even if you do not define it explicitly.
  • The component uses the NavigationManager from the framework to perform the navigation based on the value from the UrlField.

    • If you have a template that adds anchors, or use a click event to navigate the user yourself, this may lead to double navigation and errors, especially if your model has a field called Url. To avoid such problems, either let the Telerik component do the navigation and remove the application-specific code that does it as well, or remove the URL setting (either rename the model field, or point the UrlField to a non-existing field).
  • You may also find useful this article on selecting a Drawer item when a page loads.

See Also

In this article
Not finding the help you need? Improve this article