0

我正在使用以下步骤引导 KotlinJS + React 应用程序:

npm install -g create-react-kotlin-app
create-react-kotlin-app frontend
cd frontend
npm install kotlinx-coroutines-core
npm install @jetbrains/kotlin-react-router-dom

这给了我一个基本的 KotlinJS + React 应用程序

package.json我可以看到我的路由器导入

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@jetbrains/kotlin-react-router-dom": "^4.3.1-pre.61",
    "kotlinx-coroutines-core": "^1.1.0",
    "react": "^16.7.0",
    "react-dom": "^16.7.0"
  },
  "devDependencies": {
    "react-scripts-kotlin": "3.0.3"
  },
  "scripts": {
    "start": "react-scripts-kotlin start",
    "build": "react-scripts-kotlin build",
    "eject": "react-scripts-kotlin eject",
    "gen-idea-libs": "react-scripts-kotlin gen-idea-libs",
    "get-types": "react-scripts-kotlin get-types --dest=src/types",
    "postinstall": "npm run gen-idea-libs"
  }
}

几个站点上的示例显示了类似的内容,但没有使用哪个导入

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")
            }
        }
    }
}

hashRouter通过导入定义会导致

src/app/App.kt:11:3: error: unresolved reference: hashRouter
                hashRouter {
  ^

我正在尝试 Ctrl + Space,但自动完成功能一点用都没有。

我错过了哪个进口?

4

2 回答 2

1

我遇到了同样的问题,并设法使用以下步骤解决了它。

在应用程序目录中,按顺序安装以下内容。

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

  2. npm run gen-idea-libs

于 2020-01-08T00:56:01.873 回答
0

您还需要react-router-dom"在依赖项中导入。

于 2019-03-16T20:24:23.263 回答