Still, there are more changes we have to do, let see that in the next article. So, these are the couple of initial and important changes we need to consider when migrating from v.5 to v.6. And then you find an isActive property inside an object on react-router-6 and do a simple conditional ternary statement to define. You'll need to use an argument with a function to promote this change. Instead that, you need to write a most verbose code. So unlike with v.5, in v.6 the order of Routes is doesn’t matter anymore. However, what did change was the activeClassName props, it doesn't exist anymore. The reason for this is that internally, React-router-dom v.6 have a better algorithm for picking the best route to be loaded for the given path. If the incoming URL is “/product/55”, it’ll render component, it’s because the order Route which I wrote.īut in v.6, any URL which starts with /products, it should render component, at the same time, if the incoming URL is “/product/55”, it’ll render component, because we explicitly declared this Route in Routes. Once we add start at the end, this Route will become active if a URL path starts with /products, instead of being only /products.Īccording to v.5 the above routes, for eg. This going to be our first changes, in v.5 or in older versions, we used Switch component, which is provided by the react-router package to wrap all our routes and it’ll make sure that only one routes is loaded at a time. Switch is not exported from recat-router-dom If we visit the browser page to figure out what’s the error, we can see “Switch is not exported from recat-router-dom” – this would be the first error we all will get. For creating the React Routes need to use React Router DOM package.
Once router package was updated to v.6, now we can run “npm start”, we can see that the project won’t work.
We all are using react-router-dom v.5 or lower versions in our projects, we going to update router version, with the simple npm comment “npm install which ensures that you are going to install v.6, also we can “npm install – which will always give you the very latest version. Overall v.6 is a lot better than the v.5.
It’s simple to upgrade and not a lot of code change.
And they provided specifically an upgrading guide, where we can find the detailed upgrading steps and we can learn what’s new and what changed from older versions. To learn more detail about React Router v.6, you can check out the official website and the documentation you can find there. In this article, we will walk through what’s new with React Router v.6 and how we could update an existing React app, that’s using React router v.5 or lower version to React Router v.6. Version 6 of React Router is here React Router v6 takes the best features from v3, v5, and its sister project, Reach Router, in our smallest and most powerful package yet.