Created
April 17, 2026 17:28
-
-
Save AndroidPoet/440dadc93c66bcaabf585d37107f3ecf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Composable | |
| fun SyncWithBrowserHistory(navController: NavController) { | |
| val currentRoute = navController.currentBackStackEntryAsState().value?.toRoute() | |
| LaunchedEffect(currentRoute) { | |
| val url = routeToUrl(currentRoute) | |
| window.history.pushState(null, "", url) | |
| } | |
| LaunchedEffect(Unit) { | |
| window.addEventListener("popstate") { | |
| val path = window.location.pathname | |
| val route = parseUrlToRoute(path) | |
| navController.navigate(route) { | |
| popUpTo(navController.graph.startDestination) { | |
| inclusive = true | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment