reactjs - 无法解决在 reactjs 中显示为未定义状态的错误?
问题描述
我是 reactjs 的新手,我的目标是制定保护路线并通过链接https://codesandbox.io/s/github/browniefed/tmp/tree/reactRouterProtectedRoute/但在我的本地代码中我收到错误像状态没有定义。我无法弄清楚我做错了什么。
export const PrivateRoute = ({ component: Component, loggedIn, path, ...rest }) => (
<Route
path={path}
{...rest} render={props => {
// authorised so return component
return loggedIn ? (<Component {...props} />) : (<Redirect to={{
pathname: "/Signin",
state: {
prevLocation: path,
error: "You need to login first!",
},
}}
/>)
}} />
)
我收到如下快照所示的错误:
谁能帮我解决这个错误?
解决方案
你可以像这样包装你的组件 => withRouter(yourComponent);
推荐阅读
- java - 无法使用 NamedParameterJdbcTemplate 将不同的参数(例如 2 个 String(s) 和 2 个 String[] 数组参数)传递给 SQL
- android - 如何在 android 盒子上强制我的应用纵向定向?
- css - 如何在less中使用递归定义?
- svn - 导出/导入 Subversion 转储文件时维护目录结构是否重要?
- php - AJAX 正在跳过成功功能
- maven - 将插件 vaadin 上传到存储库 maven.vaadin
- java - 自定义对象树集
- sql - 必须用存储过程声明标量变量“@id”错误
- c# - 从 C# 进程运行 git clone,忽略密码短语的输入
- javascript - 未捕获的 ReferenceError:未定义 CCapture?