🚀 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!
Key Features • How To Use • Credits • License • Changelog
To use this package, you can simply install using Swift Package Manager and following these steps:
import SwiftUI
enum 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)
}
}
}
import SwiftUI
struct ContentView: View {
var body: some View {
// The RouterView is initialized with the root view of the app.
RouterView<AppRoute>(rootView: .home)
}
}
import SwiftUI
// Import the RouterKit to use in your project
import RouterKit
struct HomeView: View {
// Every view that was rendered by RouterView has a router inside
@EnvironmentObject var router: Router<AppRoute>
var body: some View {
VStack {
Button("Push view") {
router.push(to: .profile(userID: '<user-id>'))
}
Button("Push view without animation") {
router.push(to: .profile(userID: '<user-id>'), animate: false)
}
Button("Pop view") {
router.pop()
}
Button("Pop to root view") {
router.popToRoot()
}
Button("Replace root view to another") {
router.replaceRootView(to: .settings)
}
}
}
}
This project is an 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 [email protected] about anything you’d want to say about this software. I’d really appreciate it!
This package was created on Apple Developer Academy.
Apache
berkspar.com  ·Â
GitHub @berkspar  ·Â
LinkedIn in/berkspar  ·Â