varabyte / kobweb

A modern framework for full stack web apps in Kotlin, built upon Compose HTML
https://kobweb.varabyte.com
Apache License 2.0
1.41k stars 64 forks source link

Dynamic routes #48

Closed bitspittle closed 2 years ago

bitspittle commented 2 years ago

Support ways so that if the user visits a URL link like this on the site:

mystie.com/blog/12/comments/5943

and they register the URL with Kobweb like:

/blog/{blogId}/comments/{commentId}

then what happens is we can the function referenced to it like so:

@Page
fun CommentPage() {
   val ctx = rememberPageContext()
   // ctx.query["blogId"] == 12 && ctx.query["commentId"] = 5943
}

There are two potential ways I can see to make this registration (and perhaps we should support both!)

1) Allow the user to actually rename the file and directories to use curly braces:

file: myapp/pages/blog/{blogId}/comments/{CommentId}.kt

2) Allow the user to specify an override on the @Page annotation:

file: myapp/pages/blog/blogId/comments/CommentId.kt

@Page("/blog/{blogId}/comments/{commentId}"
fun CommentPage() { ... }