I'm using JetBrains Compose framework on a desktop application project, and for routing they suggest in the official documentation arkivanov-Decompose
library for routing between views (Composables).
Works like a charm, but the more views you have, the longer your routing file gets. I was wondering if I could make it look a little bit better.
I'm only familiar with web routing like in Angular, when we can define the routes inside the modules. There, every module can have a module-routes.ts
file with something like:
const routes: Routes = [
{ path: 'first-component', component: FirstComponent },
{ path: 'second-component', component: SecondComponent },
];
This way I can manage all elements that concern the module inside the module, and the routes are imported into a global Router module.
In Decompose I'm trying to do something along those lines, so I can encapsulate certain views in their respective modules (some views only interact with views of the same module, but I'm having a hard time having my router to be distributed between the modules. Does anyone have an idea on how to do it?
I have my router and my child set:
private val router =
router<Configuration, Content>(
initialConfiguration = Configuration.Auth, // Starting with Login
childFactory = ::createChild // The Router calls this function, providing the child Configuration and ComponentContext
)
and my child factory:
private fun createChild(configuration: Configuration, context: ComponentContext): Content =
when (configuration) {
is Configuration.Auth -> auth(configuration)
is Configuration.UserList -> userList()
is Configuration.NewUser-> newUser()
can I get those configs from the modules to make it cleaner? Can I have different routes for different types of user (admin, normalUser, etc...)?