4

https://github.com/reactjs/react-router/example

I tried the example on npm start

query string match to route is not working on the example. When I click the second one, It's activating wrong one

http://localhost:8080/query-params/user/bob?showAge=1 and refreshing on the link above not matching any routes.

Even if I have change the example code to below <Route path="user/:userID(?:showAge)" component={User} /> I tried couple of things that might work based on docs but none of them worked.

Am I missing something?

helloworld331
  • 166
  • 2
  • 9

2 Answers2

1

Turned out there was error on the example on react-router github.

I've made a PR for it which removes activeClassName for Link component.

without it, it works fine, and query string is in location props, see below

this.props.location.query = { 
  query1: value1,
  query2: value2
}

this picture

Mo.
  • 26,306
  • 36
  • 159
  • 225
helloworld331
  • 166
  • 2
  • 9
-1

You are missing the root (/) in path="user/:userID(?:showAge)"

This code must works:

 <Router history={history}>
    <Route path="/user/:userID/:showAge)" component={User} />
 </Router>

Check if the params are in the route:

  console.log(JSON.stringify(this.props.routeParams));

My whole file

Paul T. Rawkeen
  • 3,994
  • 3
  • 35
  • 51
aarkerio
  • 2,183
  • 2
  • 20
  • 34