Skip to content

Latest commit

 

History

History
45 lines (36 loc) · 1.24 KB

File metadata and controls

45 lines (36 loc) · 1.24 KB

kotlin-react-dom

Kotlin wrapper for React Router DOM library. Major version number of this wrapper matches that of React Router DOM itself.

Both BrowserRouter and HashRouter are supported.

Installation

  1. npm i @jetbrains/kotlin-react-router-dom

  2. npm run gen-idea-libs

See the Bintray page for Maven and Gradle installation instructions.

Examples

interface IdProps : RProps {
    var id: Int
}

class RootComponent : RComponent<RProps, RState>() {
    override fun RBuilder.render() {
        hashRouter { // or "browserRouter"
            switch {
                route("/", IndexComponent::class, exact = true)
                route("/login", strict = true) {
                    login(providers = listOf("plain", "facebook"))
                    a(href = "#/") {
                        +"Back"
                    }
                }
                route<IdProps>("/user/:id") { props ->
                    div {
                        +"User id: ${props.match.params.id}"
                    }
                }
                redirect(from = "/redirect", to = "/redirected")
            }
        }
    }
}