Phoenix router. How to match a query string?

The title says it all really.
The documentation helpfully shows:

user_path(Endpoint, :show, 17, admin: true, active: false)
“/users/17?admin=true&active=false”

Less helpfully it’s not clear to me how to match against query strings in the router. Extensive search hasn’t revealed an answer, so this might help others.

1 Like

Probably because you can’t do that. The router does match on the path, not the query params. You can however match on the params within your controllers or use forward in your router to forward the request to a custom plug, which would route based on your query param.

1 Like

Thanks Ben @LostKobrakai that helps to know