关于私有路由部分
来源:12-2 【路由进阶】私有路由搭建

慕先生5461412
2022-03-20
假设用户已登录,routeComponent返回的就是React.CreateElement(component, props),然后
PrivateRoute 就返回 <Route render={(props) => React.CreateElement(component, props)} {...rest} />,即<Route render={(props) => React.CreateElement(component, props)} path="/shoppingCart" />
为什么不能像404页面那样直接写函数而是套一层 React.CreateElement 呢?
写回答
1回答
-
阿莱克斯刘
2025-01-22
在 React 中使用 `React.createElement` 可能看起来复杂,但它有特定的作用,尤其在路由和组件动态创建方面。
使用 `React.createElement` 可以在需要动态传递 `props` 或应用高阶组件时,确保组件被正确创建和处理。而对于静态页面(如 404 页面),你可以直接传递组件,因为不需要额外的处理逻辑。00
相似问题