我在桌面应用程序项目中使用 JetBrains Compose 框架,并且对于路由,他们在官方文档arkivanov-Decompose
库中建议用于视图之间的路由(可组合)。
就像一个魅力,但你拥有的视图越多,你的路由文件就越长。我想知道我是否可以让它看起来更好一点。
当我们可以在模块内定义路由时,我只熟悉 Angular 中的 Web 路由。在那里,每个模块都可以有一个module-routes.ts
文件,如下所示:
const routes: Routes = [
{ path: 'first-component', component: FirstComponent },
{ path: 'second-component', component: SecondComponent },
];
这样我就可以在模块内部管理与模块相关的所有元素,并将路由导入到全局路由器模块中。
在分解中,我试图按照这些思路做一些事情,所以我可以将某些视图封装在它们各自的模块中(一些视图只与同一模块的视图交互,但我很难让我的路由器分布在它们之间模块。有没有人知道怎么做?
我有我的路由器和我的孩子:
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
)
和我的孩子工厂:
private fun createChild(configuration: Configuration, context: ComponentContext): Content =
when (configuration) {
is Configuration.Auth -> auth(configuration)
is Configuration.UserList -> userList()
is Configuration.NewUser-> newUser()
我可以从模块中获取这些配置以使其更清洁吗?我可以为不同类型的用户(管理员、普通用户等)设置不同的路由吗?