React-router: How to do multiple optional params with react-router?

Created on 24 Dec 2015  路  6Comments  路  Source: ReactTraining/react-router

I am working on a search page.
And the page should have some filter condition
and the url look like this in regular way:
?sort=price&type=a&rangeStart=10&rangeEnd=100
how do I make it in react-router way?

I was think about I can do it in this way, because the params is optional,
so the route could be
/search(:/sort)(:/type)(:/rangeStart)(:/rangeEnd)

but how do I know which query is passed in url, and which not?

Most helpful comment

Thanks for your question!

We want to make sure that the GitHub issue tracker remains the best place to track bug reports and feature requests that affect the development of React Router.

Questions like yours deserve a purpose-built Q&A forum. Could you post this question to Stack Overflow with the tag #react-router? https://stackoverflow.com/questions/ask?tags=react-router.

We also have an active and helpful React Router community on Reactiflux, which is a great place to get fast help with React Router and with the rest of the React ecosystem. You can join at https://discord.gg/0ZcbPKXt5bYaNQ46.

All 6 comments

Thanks for your question!

We want to make sure that the GitHub issue tracker remains the best place to track bug reports and feature requests that affect the development of React Router.

Questions like yours deserve a purpose-built Q&A forum. Could you post this question to Stack Overflow with the tag #react-router? https://stackoverflow.com/questions/ask?tags=react-router.

We also have an active and helpful React Router community on Reactiflux, which is a great place to get fast help with React Router and with the rest of the React ecosystem. You can join at https://discord.gg/0ZcbPKXt5bYaNQ46.

@littlee have a look at query params examples https://github.com/rackt/react-router/blob/master/examples/query-params/app.js

let { query } = this.props.location
let age = query && query.showAge ? '33' : ''

thanks

@icem The link is dead, can you post a working link?

So basically the lesson here is: you don't have to declare query params in a route at all, whatever queryParams exist at runtime will be available via location.query anyways. Right?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stnwk picture stnwk  路  3Comments

misterwilliam picture misterwilliam  路  3Comments

ArthurRougier picture ArthurRougier  路  3Comments

ackvf picture ackvf  路  3Comments

alexyaseen picture alexyaseen  路  3Comments