-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I make the router work with a query string? #36
Comments
My code in routes.php:
And from the view model that uses the route helper to generate a selector URL:
(I tried removing the ? from the query param and hardcoding it into the route, but that didn't fix it.) The route helper generates this URL. It's an absolute URL, but I've made it relative here for privacy reasons.
The handle method signature in the selector controller looks like this:
However, the router doesn't match the link that the route helper generates. |
It seems like the issue arises from AltoRouter->match() via Rareloop\Router\Router->match(). Router is only passing the URI path to AltoRouter, and AltoRouter->match() appears to lack support for query strings. Router line 161: |
I'm going to try converting the route to use Lumberjack-style parameters, and have the selector view model use them to generate a traditional query string to embed in a data attribute in the view. Then my JavaScript app could reference that attribute. |
That worked! It would be a good idea to add a note to the documentation for the router and route helper saying that query strings are not supported - and perhaps even a check in the route helper that throws an exception if a param value is a query string. |
What code do I need for the router to recognize an optional query string? I specifically need a query string because it will be parsed by JavaScript on the page. I tried creating two routes, one with a query string parameter and one without. The one without the query string works fine, but when the query string is present the router doesn't match the route. I looked on the Router page in the documentation but couldn't find anything about this. Can you help?
The text was updated successfully, but these errors were encountered: