私有路由的问题
来源:3-17 【讨论题】什么是 React?

聂成阳
2022-03-15
老师你好,我升级到v6版本后吗,私有路由提示报错
代码如下
const PrivateRoute = ({ component, isAuthenticated, ...rest }) => {
const RouteComponent = (props) => {
return isAuthenticated ? (
React.createElement(component, props)
) : (
<Navigate to="/signIn" />
);
};
return <Route {...rest} element={<RouteComponent />}></Route>;
};
<PrivateRoute
isAuthenticated={jwt !== null}
path="/shoppingCart"
component={ShoppingCartPage}
/>
<PrivateRoute
isAuthenticated={jwt !== null}
path="/placeOrder"
component={PlaceOrderPage}
/>
git 地址是git@github.com:niechengyang/react-ts.git
写回答
1回答
-
阿莱克斯刘
2022-03-18
同学你好,课程会在近期做一次升级,升级到router v6,react也会升级到18。在此之前请先参考一下课程的另外两个答案,http://coding.imooc.com/learn/questiondetail/qid/251663, http://coding.imooc.com/learn/questiondetail/qid/253297
你的代码我需要周末才能研究。
00
相似问题