React [email protected] upgrade to @6.x actual combat

I. Overview

At present, the version of the company's products related to react tools is generally low, and the version of react router is 3.x (yes, I read that right, the version of 3.x, the version 4 years ago). And the latest react router has reached version 6.x.

In order to be able to keep up with the pace of routing, and to use router-related hooks functions, an essential upgrade is here! Since react-touter 6.x needs to rely on react and react-dom, our project needs to meet the following conditions:

"peerDependencies": {
    "react": ">=16.8",
    "react-dom": ">=16.8"
}

Currently, the latest version of react router is 6.14.0, so make sure to use react-router-dom: 6.14.0 as the target upgrade version. Yes, the v4/v5 version is skipped, and the v6 is directly in place.

2. React Router upgrade

2.1 Component reference

In the v6 version, the react router package can be divided into 3 packages:

  • react-router : core package, only provides core routing and hook functions, will not be used directly
  • react-router-dom : API for browser/web applications. Rely on react-router and re-expose react-router API
  • react

Guess you like

Origin blog.csdn.net/xiangzhihong8/article/details/132203450