Error: A <Route> is only ever to be used as the child of <Routes> element, never rendered directly.

原因

React路由版本问题,你可以查看自己的package.json文件,查看react-router-dom的版本,应该是 6 版本。

在 React-Router v6版本中,Route更改了使用方式。

//最新语法
   
            } />
            } />
          
          {/* 5版本 */}
          
          

解决
1 切换5点几版本

npm i [email protected]

2 按照最新语法

原因

React路由版本问题,你可以查看自己的package.json文件,查看react-router-dom的版本,应该是 6 版本。

在 React-Router v6版本中,Route更改了使用方式。

//最新语法
   
            } />
            } />
          
  

你可能感兴趣的:(笔记,javascript,react.js,前端)