domkm / silk

Routing for Clojure & ClojureScript
222 stars 13 forks source link

Generate URL with query params? #28

Open cjohansen opened 7 years ago

cjohansen commented 7 years ago

Is there any way to generate a URL for a route with some additional query parameters? I would want to do something like (silk/depart routes :login {} {:query {"returnUrl" "/somewhere"}}), but AFAICT there's no way to feed query params into depart. Am I holding it wrong?

domkm commented 7 years ago

There is not. Why would you want to do that instead of encoding them into the route itself?

cjohansen commented 7 years ago

I could be convinced there's a better choice. I need to add an optional value to the generated URL - the login page takes a returlUrl query parameter, but it is not required. Also, I would prefer to encode this value as a query parameter, not part of the path, as it is optional and the page is the same.

If there's already a way to do this I'm eager to hear about it. If not, I'm hopeful you'll consider making it a feature.

livtanong commented 6 years ago

Generating a URL via query params does work, but not in the way @cjohansen wants.

(def routes
  (silk/routes [[:foo [["bar" :herp] {"baz" :burp}]]]))

(silk/depart routes :foo {:herp "derp" :burp "kangaroo"})
;; "/bar/derp?baz=kangaroo"
domkm commented 6 years ago

@cjohansen My sincere apologies for letting this slip through. I don't recall receiving a notification of your response.

@levitanong Thanks for chiming in and drawing my attention.

Would using silk/? provide the optional param functionality that you're looking for?