I think i need some help. I have two locations: ``...
# ktor
m
I think i need some help. I have two locations:
Copy code
@location("/gallery/{galleryid}/{prettyName}") class GalleryLocation(val galleryid: Int, val prettyName: String? = null) : Location
@location("/gallery/view/{pictureid}") class GalleryPictureLocation(val pictureid: Int, val overlay:String?=null) : Location
When i request with url:
/gallery/view/91270
I somehow end up
Route.handle
with a
GalleryLocation
instead of the expected
GalleryPictureLocation
. This give me a number format exception because it expects
view
to be an int given that Location.
r
The problem with URL routes is that they are all strings. Both routes you defined are essentially the same. How can it know, for example, that a {galleryId} will never be view and that they are different? It can’t. So the first match it finds is the first route and that is what is executed. Routes for the most part are just regular expressions. Try following the execution path in your head or a piece of paper for different values for {galleryid} and {prettyname}, including for something like
/gallery/view/someName
.
m
Yes you are right. Me thought was that it would prefer the second location as it was more specific - meaning no variables. So find the longest subroute that match without wildcards/variables