Do you have any tips on how to implement basic nav...
# compose-web
s
Do you have any tips on how to implement basic navigation based on
window.location.pathname
? I'd like to use single html template and make
renderComposable()
inject different DOM tree based on the current
pathname
. Web compose works on root host by default, and browser returns
Cannot GET /path-name/
when I try to reach
host/path-name/
. Is there currently any way to define supported paths so I can render different UI for them, provide 404 templates, etc?
b
Here's how to subscribe compose to external events https://www.github.com/mpetuska/kamp/tree/feature%2Fcompose/app%2Fclient%2Fsrc%2FcommonMain%2Fkotlin%2Futil%2Fcompose.kt Hook into path changes and render tree depending on that state in when statement
🙏 1
h
Or use
Copy code
@Composable
fun path(): String {
    var path by remember { mutableStateOf("") }
    SideEffect {
        path = window.location.hash.removePrefix("#")
        println("hash location" + window.location.hash)
        println("history state" + window.history.state)
    }
    return path
}
https://github.com/hfhbd/ComposeTodo/tree/main/web/src/jsMain/kotlin/app/softwork/composetodo/routing
🙏 1