Franco
08/26/2020, 12:26 AM/test/:id
) using the React Router wrapper and I can't make it work. I tried something similar to the example in the README (https://github.com/JetBrains/kotlin-wrappers/blob/master/kotlin-react-router-dom/README.md) but that doesn't work as match
can't be found when calling props.match.params.id
. Does anyone know how to do this?
This is my example:
interface IdProps : RProps {
var id: Int
}
class RootComponent : RComponent<RProps, RState>() {
override fun RBuilder.render() {
hashRouter { // or "browserRouter"
switch {
route<IdProps>("/user/:id") { child(Comp2::class) {} }
}
}
}
}
class Comp2 : RComponent<IdProps, RState>() {
override fun RBuilder.render() {
div {
+"User id: ${props.match.params.id}"
}
}
}
Franco
08/26/2020, 12:43 AMFranco
08/26/2020, 12:56 AMinterface IdProps : RProps {
var id: Int
}
class RootComponent : RComponent<RProps, RState>() {
override fun RBuilder.render() {
hashRouter { // or "browserRouter"
switch {
route<IdProps>("/user/:id") { props -> child(Comp2::class) { attrs.id = props.match.params.id } }
}
}
}
}
class Comp2 : RComponent<IdProps, RState>() {
override fun RBuilder.render() {
div {
+"User id: ${props.id}"
}
}
}
Although it's not ideal as I basically have to send the id
param explicitly to the child component 🤔. It'd be great if this was already passed implicitly like it's done in JS.