-
Hi, If I had a composable such as "topNavigationBar" that I wanted applied to all routes in addition to the component that they resolve to would this be possible? for example something like this:
this way I won't have to add topNavBarComposable to all of my components individually. also it feels weird to use noMatch to make it resolve the correct composable for example when I go to localhost:8080/about want it to load the aboutPageComposable. Am I doing this correctly? also could you explain the difference between int & intRoute, string & stringRoute and how they're supposed to be used? I don't really get it. Thanks a ton for making this, its really cool! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey @abueide, lets start with the core concept of routing first: This (common) router implementation is basically a trie router, starting with the If you want to apply the same component always on top, eg a header, one possibility would be simple calling this component before the router: topNavBarComposable()
BrowserRouter("/"){
route("/about"){
noMatch {
aboutPageComposable()
}
}
noMatch {
homePageComposable()
}
} Calling a component after the routing component, eg a footer is a little more tricky, because the footer is added some frames before the routing invocation. @Composable fun Screen(content: @Composable () -> Unit) {
topNavBarComposable()
content()
footer()
} and use it in your `Router: BrowserRouter("/") {
route("users") {
intRoute { userID ->
route("todos") {
int { todoID ->
Screen {
Text("User with ${userID.value} and todoID $todoID")
// for other cases see: https://github.com/hfhbd/routing-compose/blob/0afd6d912b9ca74a42ab71832b82248bc87986ae/src/jsTest/kotlin/app/softwork/routingcompose/IntegerRoutingTest.kt#L36
}
}
}
}
}
} The difference between Last thing regarding I hope, I answered all your questions :) |
Beta Was this translation helpful? Give feedback.
-
Hey @abueide, I just simplified the API: With BrowserRouter("/"){
topNavBarComposable()
constant("about") {
aboutPageComposable()
}
noMatch {
homePageComposable()
}
} |
Beta Was this translation helpful? Give feedback.
Hey @abueide,
lets start with the core concept of routing first:
This (common) router implementation is basically a trie router, starting with the
/
route and going down to each directly nodes (children) recursively. There are two different kind of nodes: terminal content nodes containing a@Composable
, and routing nodes, containing more nodes and finally a terminal content node. The routing nodes can not have any @composable functions! The location string (from your browser) is split by/
and the first matching node will be executed, either showing its content or, if it is a routing node, drop its starting matching route from the location string and find the first next matching node again.…