我正在使用以下步骤引导 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,但自动完成功能一点用都没有。
我错过了哪个进口?