universal-router icon indicating copy to clipboard operation
universal-router copied to clipboard

Question: how to get query parameters in route?

Open Bogdaan opened this issue 9 years ago • 5 comments
trafficstars

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.

Bogdaan avatar Dec 15 '15 17:12 Bogdaan

agreed. i'm looking into the same thing.

thehashrocket avatar Dec 15 '15 19:12 thehashrocket

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

await Router.dispatch({
  path: req.path,
  query: req.query,
}, (state, component) => {
...

Bogdaan avatar Dec 16 '15 12:12 Bogdaan

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>;
  });

aaronkw avatar Dec 16 '15 16:12 aaronkw

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

Bogdaan avatar Dec 17 '15 09:12 Bogdaan

@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

maquessime avatar Dec 17 '15 20:12 maquessime