IDotta.SimpleRouter
1.0.3
dotnet add package IDotta.SimpleRouter --version 1.0.3
NuGet\Install-Package IDotta.SimpleRouter -Version 1.0.3
<PackageReference Include="IDotta.SimpleRouter" Version="1.0.3" />
paket add IDotta.SimpleRouter --version 1.0.3
#r "nuget: IDotta.SimpleRouter, 1.0.3"
// Install IDotta.SimpleRouter as a Cake Addin #addin nuget:?package=IDotta.SimpleRouter&version=1.0.3 // Install IDotta.SimpleRouter as a Cake Tool #tool nuget:?package=IDotta.SimpleRouter&version=1.0.3
SimpleRouter
<div align="center"> <br> <a href="https://github.com/idotta/SimpleRouter"> <img width="160" heigth="160" src="./images/logo.png"> </a> <br> </div>
SimpleRouter is a lightweight and flexible routing library for .NET applications. It was inspired by ReactiveUI routing and provides a simple and intuitive API for managing navigation within your application.
Features
- Navigate to different routes in your application.
- Navigate back to the previous route.
- Navigate to a new route and reset the navigation stack.
- Use custom route factories to create routes.
Getting Started
To use SimpleRouter in your project, you'll need to create classes that implement the IRoute
and IRouterHost
interfaces. IRoute
represents a route in your application, and IRouterHost
represents the host that the router operates within.
It works pretty well with MVVM Community Toolkit, but the design is framework agnostic.
Examples can be found in the samples directory.
More advanced features are available in the SimpleRouter.Avalonia extension, which provides additional features for managing views in your Avalonia application. These can be replicated in a WPF application, for example.
Installation
You can install SimpleRouter via NuGet Package.
SimpleRouter.Avalonia
SimpleRouter.Avalonia is an extension of SimpleRouter for Avalonia applications. It provides additional features for managing views in your Avalonia application.
Features
RouteViewHost: A
TransitioningContentControl
that hosts the current route's view. It listens to route changes in theRouter
and updates the displayed content accordingly. It also supports aDefaultContent
property that is displayed when there is no current route.ViewLocatorBase: An abstract base class for view locators that implement the
IDataTemplate
interface. It provides methods for building and matching controls based on routes. It also supports aDefaultContent
property that is used when no specific control is resolved.
Usage
To use SimpleRouter.Avalonia in your project, you'll need to create a class that extends ViewLocatorBase
and implement the ResolveControl
method. This method should return the appropriate control for each route in your application.
You'll also need to add a RouteViewHost
to your Avalonia UI and bind its Router
property to your Router
instance. The RouteViewHost
will automatically update its content to match the current route.
You must create at least one ViewLocator for your application. The ViewLocator is responsible for resolving views based on routes. You can register it as a DataTemplate in App.axaml, like:
<Application.DataTemplates>
<local:ViewLocator />
</Application.DataTemplates>
You can also create different ViewLocators for different parts of your application. For example, you might have a ViewLocator for your main content and another for nested components, injecting the second directly to the RouteViewHost.
Here's an example of how you might set up a RouteViewHost
in your Avalonia UI:
xmlns:simplerouter="clr-namespace:SimpleRouter.Avalonia;assembly=SimpleRouter.Avalonia"
...
<UserControl.Resources>
<root:ViewLocator x:Key="viewLocator" />
</UserControl.Resources>
...
<simplerouter:RouteViewHost Router="{Binding Router}" ViewLocator="{StaticResource viewLocator}" />
In this example, Router
is a property in your view model and ViewLocator
is declared in your xaml file. This control can be nested inside another RouteViewHost, allowing you to create complex navigation structures.
Installation
You can install SimpleRouter.Avalonia via NuGet Package.
Running the Tests
SimpleRouter comes with a suite of unit tests. To run the tests, navigate to the SimpleRouter.Tests
directory and run the following command:
dotnet test
Contributing
We welcome contributions to SimpleRouter! Please submit a pull request with your changes.
License
SimpleRouter is licensed under the MIT License. See the LICENSE
file for more information.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on IDotta.SimpleRouter:
Package | Downloads |
---|---|
IDotta.SimpleRouter.Avalonia
Contains the IDotta.SimpleRouter platform specific extensions for AvaloniaUI. |
GitHub repositories
This package is not used by any popular GitHub repositories.