Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/berkspar/router-kit
🚀 SwiftUI Navigation Router - A lightweight and flexible SwiftUI navigation manager, built with NavigationStack and supporting customizable routes. Easily manage your app's navigation flow by pushing, popping, and replacing views. Designed to work with Routable protocol for dynamic view generation!
https://github.com/berkspar/router-kit
apple mobile router swift swiftui
Last synced: about 1 month ago
JSON representation
🚀 SwiftUI Navigation Router - A lightweight and flexible SwiftUI navigation manager, built with NavigationStack and supporting customizable routes. Easily manage your app's navigation flow by pushing, popping, and replacing views. Designed to work with Routable protocol for dynamic view generation!
- Host: GitHub
- URL: https://github.com/berkspar/router-kit
- Owner: BerkSpar
- License: apache-2.0
- Created: 2024-09-26T18:21:10.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-11-05T19:58:19.000Z (2 months ago)
- Last Synced: 2024-11-05T20:43:15.405Z (2 months ago)
- Topics: apple, mobile, router, swift, swiftui
- Language: Swift
- Homepage:
- Size: 59.6 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
RouterKit
SwiftUI Navigation Router
Key Features •
How To Use •
Credits •
License •
Changelog## Key Features
* **Protocol-Based Routing**: Define your routes using the Routable protocol for flexible and reusable navigation.
* **Dynamic View Management**: Push, pop, and replace views dynamically within the navigation stack.
* **Animated and Non-Animated Transitions**: Supports both animated and non-animated route transitions.
* **Root View Replacement**: Easily replace the root view and reset the navigation stack.
* **Navigation Stack Control**: Navigate through a NavigationStack, fully integrated with SwiftUI's native navigation system.
* **Optimized for SwiftUI**: Built with SwiftUI best practices, ensuring smooth and native integration.## How To Use
To use this package, you can simply install using **Swift Package Manager** and following these steps:
- **Step 1**: Define your app's routes by conforming to the Routable protocol.
```swift
import SwiftUIenum AppRoute: Routable {
case login
case home
case profile(userID: String)
case settings
case detail(itemID: Int)
// The builder property returns the corresponding view for each route.
var view: any View {
switch self {
case .login: LoginView()
case .home: HomeView()
case .profile(let userID): ProfileView(userID: userID)
case .settings: SettingsView()
case .detail(let itemID): DetailView(itemID: itemID)
}
}
}
```- **Step 2**: Setup the RouterView in your main view.
```swift
import SwiftUIstruct ContentView: View {
var body: some View {
// The RouterView is initialized with the root view of the app.
RouterView(rootView: .home)
}
}
```- **Step 3**: Use on each page you want.
```swift
import SwiftUI// Import the RouterKit to use in your project
import RouterKitstruct HomeView: View {
// Every view that was rendered by RouterView has a router inside
@EnvironmentObject var router: Router
var body: some View {
VStack {
Button("Push view") {
router.push(to: .profile(userID: ''))
}Button("Push view without animation") {
router.push(to: .profile(userID: ''), animate: false)
}Button("Pop view") {
router.pop()
}Button("Pop to root view") {
router.popToRoot()
}Button("Replace root view to another") {
router.replaceRootView(to: .settings)
}
}
}
}
```## Emailware
This project is an [emailware](https://en.wiktionary.org/wiki/emailware). Meaning, if you liked using this app or it has helped you in any way, I'd like you send me an email at about anything you'd want to say about this software. I'd really appreciate it!
## Credits
This package was created on [Apple Developer Academy](https://developeracademy.pucpr.br).
## Support
## You may also like...
- [Hub Finder](https://github.com/BerkSpar/hub_finder) - A social way to use Github
- [Bunnie](https://github.com/BerkSpar/bunnie) - Never forget what anime you are watching## License
Apache
---
> [berkspar.com](https://www.berkspar.com)  ·Â
> GitHub [@berkspar](https://github.com/berkspar)  ·Â
> LinkedIn [in/berkspar](https://www.linkedin.com/in/berkspar)  ·Â