From 1ca8980598aad98d918e03122add8ab523273b95 Mon Sep 17 00:00:00 2001 From: eriklimakc Date: Mon, 24 Jun 2024 18:43:37 +0100 Subject: [PATCH] docs: HowTo IRouteNotifier --- .../Advanced/HowTo-IRouteNotifier.md | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 doc/Learn/Navigation/Advanced/HowTo-IRouteNotifier.md diff --git a/doc/Learn/Navigation/Advanced/HowTo-IRouteNotifier.md b/doc/Learn/Navigation/Advanced/HowTo-IRouteNotifier.md new file mode 100644 index 000000000..09ed1f7ed --- /dev/null +++ b/doc/Learn/Navigation/Advanced/HowTo-IRouteNotifier.md @@ -0,0 +1,35 @@ +--- +uid: Uno.Extensions.Navigation.Advanced.IRouteNotifier +--- +# How-To: Use IRouteNotifier to Handle Route Changes + +The `IRouteNotifier` interface allows you to track and respond to route changes through the `RouteChanged` event. This guide will show you how to use `IRouteNotifier` to handle route changes and improve your app's navigation. + +## Step-by-steps + +> [!IMPORTANT] +> This guide assumes you used the template wizard or `dotnet new unoapp` to create your solution. If not, it is recommended that you follow the [Creating an application with Uno.Extensions article](xref:Uno.Extensions.HowToGettingStarted) for creating an application from the template. + +### How to Use `IRouteNotifier` to Monitor Route Changes + +The `IRouteNotifier` provides an effective way to monitor and respond to route changes within your application. To begin using `IRouteNotifier`, ensure your class has access to an instance of an `IRouteNotifier` implementation. Add a parameter of type `IRouteNotifier` to the constructor of your class where you want to monitor route changes. + +```csharp +public class MyClass +{ + private readonly IRouteNotifier _notifier; + + public MyClass(IRouteNotifier notifier) + { + _notifier = notifier; + _notifier.RouteChanged += RouteChanged; + } + + private async void RouteChanged(object? sender, RouteChangedEventArgs e) + { + // Implement your logic to handle route change here + } +} +``` + + \ No newline at end of file