# Do-It-Yourself Compose Multiplatform Navigation with Decompose

DevFeed: [Do-It-Yourself Compose Multiplatform Navigation with Decompose](<https://devfeed.tech/articles/do-it-yourself-compose-multiplatform-navigation-with-decompose-25916.md>)

Original publisher: [Read original article](<https://proandroiddev.com/diy-compose-multiplatform-navigation-with-decompose-94ac8126e6b5?source=rss-43bae76e8f81------2>)

Author: Isuru Rajapakse

Published: 2023-02-09T09:02:35Z

Content type: tutorial

Language: en

Sources: [Isuru Rajapakse](<https://devfeed.tech/sources/stories-by-isuru-rajapakse-on-medium.md>)

Topics: [compose-multiplatform](<https://devfeed.tech/topics/compose-multiplatform.md>), [multiplatform](<https://devfeed.tech/topics/multiplatform.md>), [Library](<https://devfeed.tech/topics/library.md>), [parcelable](<https://devfeed.tech/topics/parcelable.md>), [Process](<https://devfeed.tech/topics/process.md>)

Tags: [abstraction](<https://devfeed.tech/tags/abstraction.md>), [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [api](<https://devfeed.tech/tags/api.md>), [architecture](<https://devfeed.tech/tags/architecture.md>), [component](<https://devfeed.tech/tags/component.md>), [compose](<https://devfeed.tech/tags/compose.md>), [compose-multiplatform](<https://devfeed.tech/tags/compose-multiplatform.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [death](<https://devfeed.tech/tags/death.md>), [desktop](<https://devfeed.tech/tags/desktop.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [library](<https://devfeed.tech/tags/library.md>), [multiplatform](<https://devfeed.tech/tags/multiplatform.md>), [navigation](<https://devfeed.tech/tags/navigation.md>), [parcelable](<https://devfeed.tech/tags/parcelable.md>), [parcelize](<https://devfeed.tech/tags/parcelize.md>), [process](<https://devfeed.tech/tags/process.md>), [router](<https://devfeed.tech/tags/router.md>), [scope](<https://devfeed.tech/tags/scope.md>), [use-case](<https://devfeed.tech/tags/use-case.md>)

## AI overview

The article shows how to share Compose Multiplatform navigation between Android and Desktop using Decompose without adopting its full Component architecture. A `Router<C>` wraps Decompose's stack navigation and child stack; `RoutedContent` supplies each child's component context, and `rememberRouter` creates the stack. A `rememberViewModel` hook uses Essenty's `InstanceKeeper` to retain view models per screen and clear them when that screen leaves the stack. For process-death restoration, it pairs a `SavedStateHandle` with Essenty's `StateKeeper`; only Parcelable state can be retained this way. The approach lets the author keep a preferred architecture while using Decompose's navigation, lifecycle, and saved-state facilities. The excerpt says the implementation was also published as Decompose-Router and notes that other issues could still foil the approach.

## Source excerpt

How to survive configuration changes, survive process death and scope ViewModels without going all-in with Decompose 🫢 Decompose recently went 1.0.0 🙌. I think it's a good opportunity to share my specific use case with Decompose where I use it to share navigation logic between Android and Desktop, without going all in with Decompose's Component pattern. Here are some of the problems you would run into - in extracting the navigation to the shared code Abstraction of common navigation. Retaining and scoping your view models Restoring the view models state after the process death. Doesn't Decompose solve all these problems? Why not go all in? This was really just a preference. I wanted to do my own architecture for my app and an inheritance-based component approach wasn't my forte. Luckily Decompose allows you to use parts of it and couple your navigation with business logic (if you want to). Decompose provides you with extensive customisation options to tailor the library to your needs. That's what I ended up doing at the end An Update! 📰 I've decided to publish the implementations of this article as a library called Decompose-Router. This should save you some time if you want to implement this on your own app. If you don't care about the implementation details and just want to use the library, head over there. GitHub - xxfast/Decompose-Router: A Compose-multiplatform navigation library that leverage Decompose to create an API inspired by Conductor The Goal 🥅 This is what we will be working towards. @Parcelize sealed class Screen: Parcelable { object List : Screen() data class Details(val detail: String) : Screen() } @Composable fun ListDetailScreen() { val router: Router<Screen> = rememberRouter(listOf(List)) RoutedContent( router = router, animation = stackAnimation(slide()), ) { screen -> when (screen) { List -> ListScreen(onSelect { detail -> router.push(detail) } ) is Details -> DetailsScreen(screen.detail) } } } @Composable fun ListScreen(onSelect: (detail: Stri