reactjs / react-router-tutorial

5.52k stars 1.75k forks source link

[QUESTION] Anyway to use query parameters instead of params while defining routes? #300

Open vaidsu opened 7 years ago

vaidsu commented 7 years ago

I wish to use query parameters instead of params. I know params work and there are lessons in your tutorial. Is there any way I can pass query parameters in the routes? works with location.query, but not the routes. Am I missing anything? I did my due diligence to search for answers, but couldn't find one.

Here is my route nesting:

<Route name="Home" path="/" component={MainBlob} >
        <Route name="Comps" path="/path" component={MainTable} >
            <Route name="Runs" path="/path/v1/runs?q1=<dynamic value>&q2=<dynamic value>" component={RunsTable} />
        </Route>
        <Route name="Something" path="/path/v1/foo" component={FooTable} />
        <Route name="Users" path="/path/v1/users" component={UsersTable} />
    </Route>

Please help.

UPDATE: I tried to use router.push, which pushed the query as per doc, but still complained that route didn't exist in the declaration of routes, which is legitimate since I couldn't find a way to define a route with queries yet.