Skip to content

ChargeMap/Android-Router

Repository files navigation

Router

Router is a Android library which provides routing features to your applications.

chargemap

Maven version

License MIT Android minimum version

Installation

In your module build.gradle :

dependencies {
  implementation "com.chargemap.android:router:latestVersion"
}

Usage

Declaration

object Routes {
    object Second : Route(path = "/second")
    object Third : RouteWithParam<Third.Bundle>(path = "/third") {
        @Parcelize
        class Bundle(
            val text: String
        ) : RouteParam
    }
}

Registration

Routes.Second.register {
    Intent(it, SecondActivity::class.java)
}

or even simpler:

Routes.Second.register<SecondActivity>()

You are free to initialize your routes wherever you want but be sure to do it before pushing the associated route.

You may use App Startup or the onCreate function of a custom application registered in your manifest (see sample).

Navigation

You can push a new route from either an Activity or a Fragment

For a simple route :

Router.of(this)
	.push(
	    Routes.Second
	)

For a route with a param :

Router.of(this)
	.push(
	    Routes.Third,
	    Routes.Third.Bundle(
	        text = "Hello"
	    )
	)

Acknowledgments

This library is inspired from florent37/Navigator

Contributors

chargemap Chargemap Author