ktsu.Navigation
1.0.24
Prefix Reserved
dotnet add package ktsu.Navigation --version 1.0.24
NuGet\Install-Package ktsu.Navigation -Version 1.0.24
<PackageReference Include="ktsu.Navigation" Version="1.0.24" />
<PackageVersion Include="ktsu.Navigation" Version="1.0.24" />
<PackageReference Include="ktsu.Navigation" />
paket add ktsu.Navigation --version 1.0.24
#r "nuget: ktsu.Navigation, 1.0.24"
#:package ktsu.Navigation@1.0.24
#addin nuget:?package=ktsu.Navigation&version=1.0.24
#tool nuget:?package=ktsu.Navigation&version=1.0.24
ktsu.Navigation
A robust .NET library for implementing navigation stacks with undo/redo support and persistence capabilities.
Overview
ktsu.Navigation provides a complete navigation stack implementation that supports:
- Forward/Backward Navigation: Navigate through items with full browser-like back/forward functionality
- Undo/Redo Operations: Complete undo/redo support for all navigation actions
- Persistence: Save and restore navigation state to various storage backends
- Event-Driven Architecture: React to navigation changes with comprehensive event notifications
- Generic Design: Works with any navigation item type implementing
INavigationItem - Factory Pattern: Easy creation of navigation stacks with different configurations
Perfect for applications that need robust navigation management, such as:
- Code editors with file navigation
- Image viewers with browsing history
- Document management systems
- Any application requiring navigation state management
Features
Core Navigation
- ✅ NavigateTo, GoBack, GoForward operations
- ✅ Current item tracking with CanGoBack/CanGoForward status
- ✅ Complete navigation history management
- ✅ Forward history clearing when navigating to new items
- ✅ Thread-safe operations
Undo/Redo System
- ✅ Full undo/redo support for navigation operations
- ✅ Configurable history size limits
- ✅ State change notifications
- ✅ Error handling during undo/redo operations
Persistence
- ✅ JSON file persistence provider
- ✅ In-memory persistence for testing
- ✅ Async operations with cancellation token support
- ✅ Custom persistence provider support
Events & Extensibility
- ✅ Navigation change events (NavigateTo, GoBack, GoForward, Clear)
- ✅ Metadata support for navigation items
- ✅ Generic design for custom navigation item types
- ✅ Factory pattern for easy configuration
Installation
Add the NuGet package:
dotnet add package ktsu.Navigation
Quick Start
Basic Navigation
using ktsu.Navigation.Models;
using ktsu.Navigation.Services;
// Create navigation items
var page1 = new NavigationItem("page1", "Home Page");
var page2 = new NavigationItem("page2", "About Page");
var page3 = new NavigationItem("page3", "Contact Page");
// Create a navigation stack
var navigation = new Navigation<NavigationItem>();
// Navigate through items
navigation.NavigateTo(page1); // Current: Home Page
navigation.NavigateTo(page2); // Current: About Page
navigation.NavigateTo(page3); // Current: Contact Page
// Go back and forward
var previous = navigation.GoBack(); // Current: About Page
var next = navigation.GoForward(); // Current: Contact Page
// Check navigation state
Console.WriteLine($"Current: {navigation.Current?.DisplayName}");
Console.WriteLine($"Can go back: {navigation.CanGoBack}");
Console.WriteLine($"Can go forward: {navigation.CanGoForward}");
With Undo/Redo Support
using ktsu.Navigation.Services;
// Create navigation with undo/redo support
var undoRedoProvider = new SimpleUndoRedoProvider(maxHistorySize: 50);
var navigation = new Navigation<NavigationItem>(undoRedoProvider);
navigation.NavigateTo(page1);
navigation.NavigateTo(page2);
// Undo the last navigation
undoRedoProvider.Undo(); // Back to page1
// Redo the navigation
undoRedoProvider.Redo(); // Forward to page2 again
With Persistence
using ktsu.Navigation.Services;
// Create navigation with JSON file persistence
var persistenceProvider = new JsonFilePersistenceProvider<NavigationItem>("navigation-state.json");
var navigation = new Navigation<NavigationItem>(undoRedoProvider: null, persistenceProvider: persistenceProvider);
navigation.NavigateTo(page1);
navigation.NavigateTo(page2);
// Save navigation state
await navigation.SaveStateAsync();
// Later... restore navigation state
await navigation.LoadStateAsync();
Console.WriteLine($"Restored to: {navigation.Current?.DisplayName}");
Complete Example with All Features
using ktsu.Navigation.Services;
// Create providers
var undoRedoProvider = new SimpleUndoRedoProvider();
var persistenceProvider = new JsonFilePersistenceProvider<NavigationItem>("app-navigation.json");
// Create navigation with all features
var navigation = new Navigation<NavigationItem>(undoRedoProvider, persistenceProvider);
// Subscribe to navigation events
navigation.NavigationChanged += (sender, e) =>
{
Console.WriteLine($"Navigation: {e.NavigationType}");
Console.WriteLine($"From: {e.PreviousItem?.DisplayName ?? "None"}");
Console.WriteLine($"To: {e.CurrentItem?.DisplayName ?? "None"}");
};
// Use factory for easier creation
var factory = new NavigationStackFactory(undoRedoProvider);
var anotherNavigation = factory.CreateNavigationStack<NavigationItem>(undoRedoProvider, persistenceProvider);
Custom Navigation Items
public class DocumentNavigationItem : INavigationItem
{
public string Id { get; }
public string DisplayName { get; set; }
public DateTime CreatedAt { get; }
public IReadOnlyDictionary<string, object> Metadata => _metadata.AsReadOnly();
private readonly Dictionary<string, object> _metadata = new();
public DocumentNavigationItem(string filePath, string displayName)
{
Id = filePath;
DisplayName = displayName;
CreatedAt = DateTime.UtcNow;
SetMetadata("FilePath", filePath);
SetMetadata("FileSize", new FileInfo(filePath).Length);
}
public void SetMetadata(string key, object value) => _metadata[key] = value;
public bool RemoveMetadata(string key) => _metadata.Remove(key);
}
// Use with navigation
var navigation = new Navigation<DocumentNavigationItem>();
var document = new DocumentNavigationItem("/path/to/file.txt", "My Document");
navigation.NavigateTo(document);
Architecture
The library follows clean architecture principles with well-separated concerns:
- Models:
NavigationItem,NavigationState- Core data structures - Contracts: Interfaces defining the contracts for all components
- Services: Implementation classes for navigation, persistence, and undo/redo
Key Interfaces
INavigation<T>: Main navigation operations interfaceINavigationItem: Contract for items that can be navigated toIPersistenceProvider<T>: Contract for persistence implementationsIUndoRedoProvider: Contract for undo/redo implementations
Extension Points
Create custom persistence providers by implementing the IPersistenceProvider<T> interface:
public class DatabasePersistenceProvider<T> : IPersistenceProvider<T> where T : INavigationItem
{
public async Task SaveStateAsync(INavigationState<T> state, CancellationToken cancellationToken = default)
{
// Save to database
await Task.CompletedTask;
}
public async Task<INavigationState<T>?> LoadStateAsync(CancellationToken cancellationToken = default)
{
// Load from database
return await Task.FromResult<INavigationState<T>?>(null);
}
// Implement HasSavedState, ClearState, etc.
}
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License. Copyright (c) ktsu.dev
| 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. 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.0
- System.Memory (>= 4.6.3)
- System.Text.Json (>= 10.0.11)
- System.Threading.Tasks.Extensions (>= 4.6.3)
-
.NETStandard 2.1
- System.Text.Json (>= 10.0.11)
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.24 | 71 | 8/26/2026 |
| 1.0.23 | 97 | 8/21/2026 |
| 1.0.22 | 100 | 8/19/2026 |
| 1.0.21 | 89 | 8/19/2026 |
| 1.0.20 | 88 | 8/17/2026 |
| 1.0.19 | 96 | 8/13/2026 |
| 1.0.18 | 95 | 8/12/2026 |
| 1.0.18-pre.1 | 57 | 8/12/2026 |
| 1.0.17 | 88 | 8/12/2026 |
| 1.0.16 | 92 | 8/12/2026 |
| 1.0.15 | 86 | 8/11/2026 |
| 1.0.14 | 131 | 7/1/2026 |
| 1.0.13 | 107 | 6/30/2026 |
| 1.0.12 | 96 | 6/29/2026 |
| 1.0.11 | 108 | 6/28/2026 |
| 1.0.10 | 110 | 6/28/2026 |
| 1.0.9 | 125 | 2/16/2026 |
## v1.0.24 (patch)
Changes since v1.0.23:
- ci: make the SonarQube quality gate opt in [patch] ([@matt-edmondson](https://github.com/matt-edmondson))
- ci: adopt the unified dotnet workflow [patch] ([@matt-edmondson](https://github.com/matt-edmondson))