Breadcrumb for Navigation
The Breadcrumb can be used to navigate between different pages in the application. It can generate the needed links for you through its UrlField
when data binding.
In some cases you might prefer to dynamically generate the breadcrumbs based on the current application Url
. For this scenario you can use the NavigationManager
that the component supports and subscribe to its LocationChanged
event. Thus, you can set new Breadcrumb items on every location change.
-
Add the Breadcrumb to your application.
- You may want to add it in the
MainLayout.razor
outside of the@Body
, for example, in themain
container of your app.
- You may want to add it in the
Inject a
NavigationManager
instance in the file where you want to build the breadcrumbs.Handle the
LocationChanged
event of theNavigationManager
.Dynamically generate the Breadcrumb items based on the
Url
provided by theLocation
field of theLocationChangedEventArgs
.
Here is an example for such a configuration in our public repository - SubScribeToLocationChanged.
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 theUrlField
.- 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 theUrlField
to a non-existing field).
- 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