silk icon indicating copy to clipboard operation
silk copied to clipboard

Generate URL with query params?

Open cjohansen opened this issue 8 years ago • 4 comments

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?

cjohansen avatar Feb 27 '17 11:02 cjohansen

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

domkm avatar Feb 28 '17 05:02 domkm

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.

cjohansen avatar Feb 28 '17 05:02 cjohansen

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"

livtanong avatar Jul 25 '17 05:07 livtanong

@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?

domkm avatar Jul 26 '17 23:07 domkm