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.
To use the Breadcrumb and dynamically generate its items:
-
Add the Breadcrumb to your application.
- You may want to add it in the
MainLayout.razoroutside of the@Body, for example, in themaincontainer of your app.
- You may want to add it in the
-
Inject a
NavigationManagerinstance in the file where you want to build the breadcrumbs. -
Handle the
LocationChangedevent of theNavigationManager. -
Dynamically generate the Breadcrumb items based on the
Urlprovided by theLocationfield of theLocationChangedEventArgs.
Here is an example for such a configuration in our public repository - SubScribeToLocationChanged.
Notes
-
The
UrlFieldhas 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
NavigationManagerfrom 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 theUrlFieldto 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