Skip to content

Commit

Permalink
Drop leading ? from query
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Sep 19, 2023
1 parent 2d39818 commit d5b635a
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ inline fun <reified R : Any> routeHandler(body: (R) -> Unit) {
"Specified type must be resource"
}
val pattern = format.encodeToPathPattern(serializer)
if (window.location.pathname.replaceLeadingSlash() != pattern) return
if (window.location.pathname.dropLeadingSlash() != pattern) return

val parameters = window.location.search.parseUrlEncodedParameters()
val parameters = window.location.search.dropLeadingQuery().parseUrlEncodedParameters()
val resources = format.decodeFromParameters(serializer, parameters)

body(resources)
Expand All @@ -48,10 +48,15 @@ inline fun <reified R : Any> ComposeRouteHandler(crossinline content: @Composabl
}

@PublishedApi
internal fun String.replaceLeadingSlash() = replaceFirstChar {
if (it == '/') {
internal fun String.dropLeadingSlash() = dropLeading('/')
@PublishedApi
internal fun String.dropLeadingQuery() = dropLeading('?')

@PublishedApi
internal fun String.dropLeading(char: Char) = replaceFirstChar {
if (it == char) {
""
} else {
it.toString()
}
}
}

0 comments on commit d5b635a

Please sign in to comment.