A platform & framework agnostic kotlin multiplatform library pack that you can use to navigate though different destinations of your application.
With captain, you can do all your navigation from your business logic (which should be in common code) and do your routing in the ui layer (which depending on your tech stack, may or may not be in common code)
Router {
AppNavigation()
Routes {
Route("/") { Home() }
Route("/settings") { Settings() }
Route("/profile/{uid}") { (uid) ->
Profile(uid)
}
}
}
<Router>
<AppNavigation />
<Routes>
<Route path="/" element={<Home/>} />
<Route path="/settings" element={<Settings/>} />
<Route path="/profile/{uid}" element={<Profile/>} />
</Routes>
</Router>
Router {
AppNavigation()
Routes {
Route("/", Home)
Route("/settings", Settings)
Route("/profile/{uid}", Profile)
}
}
repositories {
mavenCentral()
}
dependencies {
// for compose-multiplatform
implementation("tz.co.asoft:captain-router-compose-core:2.0.18")
// for compose-html use
implementation("tz.co.asoft:captain-router-compose-html:2.0.18")
}
repositories {
mavenCentral()
}
dependencies {
// for react-core (can be used even in react-native applications)
implementation("tz.co.asoft:captain-router-react-core:2.0.18")
// for react-dom (can be used even in react-dom applications)
implementation("tz.co.asoft:captain-router-react-dom:2.0.18")
}
Navigator.kt
expect fun getNavigator(): Navigator
NavigatorUtils.kt
fun goTo(destination: String = "/") {
val nav: Navigator = getNavigator()
nav.navigate(destination)
}
fun goBack() {
val nav: Navigator = getNavigator()
nav.go(-1)
}
fun goForward() {
val nav: Navigator = getNavigator()
nav.go(1)
}
dependencies {
implementation("tz.co.asoft:captain-navigator-api:2.0.18")
}
To use the browser's history api and follow the address bar and back/forward presses
private val navigator = BrowserNavigator()
// to avoid creating a new navigator everytime we call getNavigator
actual fun getNavigator(): Navigator = navigator
dependencies {
implementation("tz.co.asoft:captain-navigator-browser:2.0.18")
}
private val navigator = BasicNavigator()
// to avoid creating a new navigator everytime we call getNavigator
actual fun getNavigator(): Navigator = navigator
dependencies {
implementation("tz.co.asoft:captain-navigator-basic:2.0.18")
}
Full documentation will be published soon
The full api reference of the kollections can be found at https://asoft-ltd.github.io/captain
There are multiple ways you can support this project
If you found it useful, just give it a star
You can help by submitting pull request to available open tickets on the issues section
This makes it easier to catch bugs and offer enhancements required
- andylamax - The author