If youd like to get a head start on upgrading to the next major version of React Router, there are a few things you can do today assuming youre on both React > 16.8 and React Router 5.1.
I hope this article is very useful for you. Just likeWe already covered pretty much all-important changes with v.5 to v.6, lets continue this with the next article. from ‘react-router-dom’Īfter these changes, we don’t get the above error anymore. But both props wok in a special way when applied to NavLink.ĬlassName prop in NavLink does not just take the class name, instead, it takes a function which we can pass inside className prop, and this function will give us some information about the link and the current state of navigation. Doing that is very simple, because still we can use the className prop or the style prop to apply the dynamic CSS style. Line 42 will be our main focus for this blog post. On line 42, we have the dynamic route that allows for each shirt to render.
![react router dom dynamic routes react router dom dynamic routes](https://blog.logrocket.com/wp-content/uploads/2020/08/finalproduct.gif)
Doing so tells React to render the Home component only when the url path exactly matches the one defined. Instead, if we want to apply specific class once the link became active, we have to find out manually, whether this link is active or not. On line 41, we have a route defined for the Home component. With Router v.6, activeClassName prop is removed. With Router v.5 we could use this prop to apply some CSS class automatically to the link once the link became active. Navlink is moreover same as v.5, however, what did change in v.6 is the activeClassName prop.
![react router dom dynamic routes react router dom dynamic routes](https://miro.medium.com/max/1400/1*MRJ-EGxwP7vFVkJ0dKh4zg.png)
![react router dom dynamic routes react router dom dynamic routes](https://media.geeksforgeeks.org/wp-content/uploads/20191130163843/geeks_21.png)
We still have the Link component in v.6, which generally works as you learned in v.5, there is no change. In the previous article, we saw the initial and important changes we need to consider when migrating from react-router-dom v.5 to v.6.