kriasoft / universal-router

A simple middleware-style router for isomorphic JavaScript web apps
https://www.kriasoft.com/universal-router/
MIT License
1.71k stars 104 forks source link

Question: how to get query parameters in route? #18

Open Bogdaan opened 8 years ago

Bogdaan commented 8 years ago

For example i have route "/search" and 100 parameters in app logic, how to pass this in "state"? Just for process routes like:

/search?form[a]=1&form[b]=1&form[c]=4

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

thehashrocket commented 8 years ago

agreed. i'm looking into the same thing.

Bogdaan commented 8 years ago

@jshultz as a alternative, you can pass express query string in route state:

await Router.dispatch({
  path: req.path,
  query: req.query,
}, (state, component) => {
...
aaronkw commented 8 years ago

There's an example here that might be useful: https://github.com/kriasoft/react-starter-kit/blob/master/docs/recipes/how-to-implement-routing.md#step-3-parameterized-routes

on('/products/:id', async (req) => {
    const data = await http.get(`/api/products/${req.params.id}`);
    return <Layout><ProductInfo {...data} /></Layout>;
  });
Bogdaan commented 8 years ago

@aaronkw how it will help process routes with query string (like ?form[a]=1&form[b]=1&form[c]=4)?

maquessime commented 8 years ago

@Bogdaan thanks for the advice

To clarify, here is the example with the react starter kit : https://github.com/kriasoft/react-starter-kit/pull/355