Skip to content
Advertisement

React-router get optional query parameter

i have been looking into some examples on stack overflow for defining optional query params in react-router and finally found out that it can be done like

JavaScript

so at next step i want to retrive the query param that is “journyeId” if it is there, so i tried with

JavaScript

but that doesn’t seems to work, what should be the workaround for this ??

“react-router”: “^5.1.2”, “react-router-dom”: “^5.1.2”,

Advertisement

Answer

there is a hook for this: useParams from react-router-dom

JavaScript

After that, in NewsPage component I will be able to grab an ID from route like this:

JavaScript

And so on

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement