错误警告信息
1 |
Failed prop type: Invalid prop 'component' supplied to 'Route': the prop is not a valid React component |
一般是React-router-dom 4.0+路由跳转时出现警告,主要是因为语法使用上面有所改变,在声明路由的时候要使用新的方式
老版本路由声明:
1 2 3 4 |
import Home from "@/pages/home/home.jsx"; import Detail from "@/pages/detail/detail.jsx"; <Route path="/" exact component={Home}></Route> <Route path="/detail/:id" exact component={Detail}></Route> |
新版本路由声明(改造成此方式):
里面是一个函数式,记的把porps带给组件中去
1 2 |
<Route path="/home/" exact component={(props) => <Home {...props} />}></Route> <Route path="/detail/:id" exact component={(props) => <Detail {...props} />}></Route> |