A class that defines a path to the screen. The properties of this class are parameters that you want to send to the screen. Use a simple class when the path doesn't provide any parameters to the screen. Use a data class when you want to pass one or more parameters. Avoid passing heavy data like images or long arrays through it. It is usually used to pass small portions of data such as IDs or filter parameters.
Examples:
classMainPath: RoutePath//Simple pathdataclassStepPath(val step: Int): RoutePath//Path with parametersdataclassDialogPath(val title: String="",val message: String="",val okBtn: String="",val cancelBtn: String=""): RoutePathResult<Boolean> //Path with parameters that returns Boolean value
RouteController
A class that connects RoutePath, Screen, and serves to implement custom routing logic. This class is marked with the @Route annotation and implements one of the children of the RouteControllerInterface. Currently, we have four predefined RouteController classes:
Simple with only Fragment or Compose as view RouteController
With only Fragment or Compose as View and Dagger injection RouteControllerC. The letter C means Component that passes in the Controller for injection
Fragment or Compose as View and ViewModel RouteControllerVM. VM means ViewModel
Fragment or Compose as View and ViewModel and Dagger injection RouteControllerVMC
By default this class should be abstract because all its method generated by the framework. You can override its if you need to do some extra action, for example add something to the Bundle of the Fragment.
Examples:
classSimplePath: RoutePath@RouteabstractclassSimpleRouteController: RouteController<SimplePath, SimpleScreen>()// Then somewhere in coderouter.route(SimplePath())
dataclassSimplePath(val title: String): RoutePath@RouteclassSimpleRouteController: RouteController<SimplePath, SimpleScreen>(){overridefunonCreateView(path: SimplePath): SimpleScreen=// logic of creation of the appropriate Screen}// Then somewhere in coderouter.route(SimplePath("I'm a title"))
Simple scheme
Example for Fragment
Example with no parameters to transfer
classSimplePath: RoutePath@RouteabstractclassSimpleRouteController: RouteController<SimplePath, SimpleFragment>()// Then somewhere in a Fragment or ViewModelrouter.route(SimplePath())
With parameters
dataclassSimplePath(val title: String): RoutePath@RouteclassSimpleRouteController: RouteController<SimplePath, SimpleFragment>(){overridefunonCreateView(path: SimplePath): SimpleFragment=SimpleFragment().apply { arguments =Bundle().apply { // Put some data to BundleputString("TITLE_KEY", path.title) } }}// Then somewhere in a Fragment or ViewModelrouter.route(SimplePath("I'm a title"))
classSimplePath: RoutePath@RouteabstractclassSimpleRouteController: RouteController<SimplePath, SimpleView>()// Then somewere in a Compose viewLocalRouter.currentOrThrow.route(SimplePath())// Or in a ViewModelrouter.route(SimplePath())
With parameters
dataclassSimplePath(val title: String): RoutePath@RouteclassSimpleRouteController: RouteController<SimplePath, SimpleView>(){overridefunonCreateView(path: SimplePath): SimpleView=SimpleView(path.title)}// Then somewere in a Compose viewLocalRouter.currentOrThrow.route(SimplePath("I'm a title"))// Or in a ViewModelrouter.route(SimplePath("I'm a title"))