Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to wrap react bootstrap in react router?


Asked by Kabir Dickerson on Dec 10, 2021 React



For React Router v3 or lower (see rr-v3 branch): Wrap your React Bootstrap element in a <LinkContainer> to make it behave like a React Router <Link> Please note that by default React Router will match any location that contains path specified in to prop.
Just so,
Any answer here which suggests nesting a html button in a React Router Link component (or vice-versa) will render in a web browser, but it is not semantic, accessible, or valid html: This can lead to layout/styling issues as buttons are not typically placed inside links.
Besides, Yes you do have to set up react-router as if you were not using react-router-bootstrap. For your application (guessing you just want same level paths with the NavItens u set) I think it will be something like this (assuming that you're rendering your app's component in a div with id="app"):
Also Know,
In react, you can use react-router-dom by applying the useHistory call... I recommend that you utilize the component prop on the Link component. Using this, you can have effectively any component behave as an a component from the perspective of React Rotuer.
Similarly,
React Router provides some props to your components, including the push () function on history which works pretty much like the < Link to='path' > element. You don't need to wrap your components with the Higher Order Component "withRouter" to get access to those props.