0

I want to add attributes on my <Route> from react-router-dom. When I just add it inside the path, the default route is fired instead. An example of what I would like to work, but do not, since the default route is used instead:

        <Route path="/myurl?myattribute=attributevalue"><MyComponent /></Route>

It seems like the Route path do get confused with the questionmark. If I just change it to something else, like an amperstamp, it "works". However, It is not that format I want. I want the regular ?

I can not find documentation on how I can make something like this work. I have seen something about the :id part of the url, but I do not quite understand it.

Thank you for all help

RMT
  • 560
  • 1
  • 7
  • 20
  • Remove `exact` works for this – keikai Mar 02 '20 at 07:25
  • Woops, I forgot to remove it from the question. I have tried both, with and without, but neighter works @keikai – RMT Mar 02 '20 at 07:26
  • See here https://stackoverflow.com/questions/43216569/how-to-get-query-parameters-in-react-router-v4. You can use search parame inside your consumer component – gadi tzkhori Mar 02 '20 at 07:42

1 Answers1

0

We don’t need to define query params in the route definition because by default it will be handled by the react router and send the query params into a props to the component

Check this out :

https://learnwithparam.com/blog/how-to-handle-query-params-in-react-router/

More Info:

How to set route with optional query parameter using React router?

VJR08
  • 5,503
  • 5
  • 21
  • 48