1.6 KiB
title | description | type | page_title | slug | position | tags | ticketid | res_type |
---|---|---|---|---|---|---|---|---|
How to select drawer item if menu page is opened by using its URL | How to select the correct drawer item when you don't navigate with the drawer | troubleshooting | Sync Drawer item selection with external navigation | drawer-kb-sync-selected-item | 1530772 | kb |
Environment
Product | Drawer for Blazor |
Description
I'm using the Drawer component for navigation purposes.
A click on a Drawer item calls the sub page as intended.
However if I call a sub page directly by URL, the corresponding Drawer item doesn't get selected.
It might be confusing for a user if they open a sub page directly and no Drawer item gets selected.
Is there a way to "fix" this issue?
Possible Cause
The Drawer selects (highlights) the item based on interaction with its own markup (such as a click on the item the user wants to navigate to). If you navigate by other means in the application, the component cannot capture this action and it does not update the selected item.
Solution
In such cases you must update the selected item with the application logic when necessary. For example, you can hook to the NavigationManager's LocationChanged event and get the current page, find a corresponding item (you can also add any relevant business logic) and set it to the SelectedItem
of the Drawer.
You can find a sample project here: https://github.com/telerik/blazor-ui/tree/master/drawer/select-on-load