首页 > 解决方案 > “无法读取未定义的属性 '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 用于后端。这是关于后端的错误吗?

标签: node.jsreactjs

解决方案


这是因为它无法_iduser对象中找到。所以你可以这样做以确保已经有user对象

<Link
      to={`users/${isAuthenticated().user && isAuthenticated().user._id}`}
    >

推荐阅读