react-router vs react-router-dom, when to use one or the other?

react-router contains all the common components between react-router-dom and react-router-native. When should you use one over the other? If you’re on the web then react-router-dom should have everything you need as it also exports the common components you’ll need. If you’re using React Native, react-router-native should have everything you need for the same reason. So … Read more

How to get parameter value from query string?

React Router v6, using hooks In react-router-dom v6 there’s a new hook named useSearchParams. So with you will get “blablabla”. Note, that searchParams is an instance of URLSearchParams, which also implements an iterator, e.g. for using Object.fromEntries etc. React Router v4/v5, without hooks, generic React Router v4 does not parse the query for you any more, but … Read more

How do I avoid ‘Function components cannot be given refs’ when using react-router-dom?

NavLink from react-router is a function component that is a specialized version of Link which exposes a innerRef prop for that purpose. You could’ve also searched our docs for react-router which leads you to https://mui.com/getting-started/faq/#how-do-i-use-react-router which links to https://mui.com/components/buttons/#third-party-routing-library. The last link provides a working example and also explains how this will likely change in … Read more

React-Router : What is the purpose of IndexRoute?

In the top example, going to / would render App with Home passed as a child. In the bottom example, going to / would render App with neither Home nor About being rendered, since neither of their paths match. For older versions of React Router, more information is available on associated version’s Index Routes and Index Links page. Starting in version 4.0, React Router no longer uses the IndexRoute abstraction to achieve the … Read more

Cannot read property ‘getHostNode’ of null

I was facing a similar issue. It turns out that, in my case, was highlighthjs removing comments from the generated dom. For text, React 15 is adding comment with the reactid instead of a span tag, as in: Can you try something like this? <Link className=”dark button” to=”/”><span>Another Search</span></Link> This will force the generated DOM … Read more