Skip to content
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

Query params #9

Closed
jacwright opened this issue May 26, 2019 · 3 comments
Closed

Query params #9

jacwright opened this issue May 26, 2019 · 3 comments

Comments

@jacwright
Copy link
Contributor

Would you be open to a contribution that supported query params?

It would be removing the query string from the end of the uri sent to run before looking for matching routes, then splitting they query string into its key-value pairs and sending those as a second parameter to the route function. E.g.

router.on('/users', (params, query) => {
  // use query params to sort, filter, etc the user list.
  const { sort, filter, limit } = query;
  ...
}
@lukeed
Copy link
Owner

lukeed commented May 26, 2019

I don't think so, no. The query prams are easily accessed on location from anywhere and they have no effect on routing/matching.

Unlike pathnames and base, there'd be nothing thru navaid that says you want to only limit/key sort sometimes but not others.

All that stuff (parsing) happens inside the route handler, and only once the pathname has been matching the first place... And should only happen if you wanted to happen.

import { decode } from 'qss';

navaid()
  .on('/users/:id?', params => {
    console.log('user id, if any', params.id);
    const { sort, filter, limit } = decode(location.search.substring(1));
    // ... Or use UURLSearchParams if you want
    // It's your choice, as it should be
  })

@jacwright
Copy link
Contributor Author

jacwright commented May 26, 2019

Adding a query string currently breaks the path matching, so to use it navaid needs to at least drop it from uri before matching against routes. I agree with you, the decoding should happen in the handler. I like that better.

@lukeed
Copy link
Owner

lukeed commented Jun 3, 2019

Thanks for the report @jacwright 👍

@lukeed lukeed closed this as completed in 1062d25 Jun 3, 2019
lukeed added a commit that referenced this issue Jun 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants