Skip to content

Commit 3ba4e8f

Browse files
committed
Add router to experiments
1 parent 222a530 commit 3ba4e8f

File tree

4 files changed

+50
-9
lines changed

4 files changed

+50
-9
lines changed

build.gradle.kts

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ repositories {
1717
kotlin {
1818
js {
1919
browser {
20+
commonWebpackConfig {
21+
cssSupport {
22+
enabled.set(true)
23+
}
24+
}
2025
}
2126
binaries.executable()
2227
}
@@ -36,6 +41,8 @@ kotlin {
3641
implementation(libs.kotlinx.serialization.json)
3742
implementation(compose.runtime)
3843
implementation(compose.html.core)
44+
implementation(libs.router)
45+
implementation(npm("hiq", "4.2.11"))
3946
}
4047

4148
jsTest.dependencies {

gradle/libs.versions.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kotlin = "2.0.0"
33
compose = "1.6.11"
44
kotlinx-html = "0.11.0"
55
kotlinx-serialization = "1.6.0"
6-
6+
router = "0.2.14"
77

88
[libraries]
99
kotlin-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.strictly = "1.8.0" }
@@ -16,6 +16,8 @@ kotlinx-html = { module = "org.jetbrains.kotlinx:kotlinx-html", version.ref = "k
1616
kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinx-serialization" }
1717
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
1818

19+
router = { module = "app.softwork:routing-compose", version.ref = "router" }
20+
1921
[plugins]
2022
jetbrains-compose = { id = "org.jetbrains.compose", version.ref = "compose" }
2123
jetbrains-compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }

src/jsMain/kotlin/Application.kt

+36-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import androidx.compose.runtime.getValue
22
import androidx.compose.runtime.mutableStateOf
33
import androidx.compose.runtime.remember
44
import androidx.compose.runtime.setValue
5+
import app.softwork.routingcompose.BrowserRouter
6+
import app.softwork.routingcompose.NavLink
7+
import app.softwork.routingcompose.Router
58
import common.BaseStyles
69
import common.Theme
710
import common.ThemeProvider
@@ -47,14 +50,39 @@ fun main() {
4750
}
4851
}
4952
PageContent {
50-
var counter: Int by remember { mutableStateOf(0) }
51-
Div {
52-
Text("Hello World $counter")
53-
}
54-
Div {
55-
Span {
56-
components.Button("Increment") {
57-
counter++
53+
BrowserRouter("/") {
54+
route("/") {
55+
NavLink("/hello-world") {
56+
Text("To Hello world!")
57+
}
58+
}
59+
route("/hello-world") {
60+
val params = parameters?.map
61+
var counter: Int by remember { mutableStateOf(0) }
62+
Div {
63+
params?.map {
64+
Div {
65+
Span { Text("Param: ${it.key}: ${it.value}") }
66+
}
67+
}
68+
}
69+
Div {
70+
Text("Hello World $counter")
71+
}
72+
Div {
73+
Span {
74+
components.Button("Increment") {
75+
counter++
76+
}
77+
}
78+
}
79+
Div {
80+
Span {
81+
val router = Router.current
82+
components.Button("Back") {
83+
router.navigate("/")
84+
}
85+
}
5886
}
5987
}
6088
}

webpack.config.d/devServerConfig.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
config.devServer = {
2+
...config.devServer, // Merge with other devServer settings
3+
"historyApiFallback": true
4+
};

0 commit comments

Comments
 (0)