node.js - “无法读取未定义的属性 'id'”错误
问题描述
export const isAuthenticated = () =>
{ if (typeof window == 'undefined') {
return false; }
if (localStorage.getItem('jwt')) {
return JSON.parse(localStorage.getItem('jwt')); }
else { return false; }
};
我将 react js 用于前端,将 node js 用于后端。这是关于后端的错误吗?
解决方案
这是因为它无法_id
在user
对象中找到。所以你可以这样做以确保已经有user
对象
<Link
to={`users/${isAuthenticated().user && isAuthenticated().user._id}`}
>
推荐阅读
- python - 如何读取每行具有不同列的文件?
- java - 如何从 Spring Data JPA NativeQuery 接收一个集合?[导致 NotReadablePropertyException]
- sql - 选择日期最高的行
- phabricator - arc diff --update 总是创建新评论
- java - defineClass 方法抛出 java.lang.ClassFormatError: Incompatible magic value 1885430635 in class file
- reactjs - socket.io 连接不适用于 react.js
- node.js - 我的 node.js 代码在 aws-lambda 中工作不稳定,有时工作正常,有时会跳过那段代码的数据持久性
- caching - 兵马俑服务器阵列如何存储数据?
- charts - 如何修复 Vue.js(laravel) 中的“Elastigantt is not defined”错误
- image - 使用 Flutter 将 n 个图像上传到 Firebase