我使用以下步骤引导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 +空格键,但是自动完成功能根本没有用。
我缺少什么进口商品?
答案 0 :(得分:1)
我遇到了同样的问题,并设法通过以下步骤解决了这个问题。
在应用程序目录中,依次安装以下内容。
npm i @jetbrains/kotlin-react-router-dom
npm run gen-idea-libs
答案 1 :(得分:0)
您还需要在依赖项中导入react-router-dom"
。