Reactjs ×;TypeError:无法读取属性';地点';未定义的
我是js新手,我在Reactjs ×;TypeError:无法读取属性';地点';未定义的,reactjs,Reactjs,我是js新手,我在this.state={location:props.history.location}行中遇到一个错误 asTypeError:无法读取未定义的属性“location”,如何解决提供以下我的代码的问题: function App() { return ( //BEM naming convention <div className="app"> <div className
this.state={location:props.history.location}行中遇到一个错误代码>
asTypeError:无法读取未定义的属性“location”
,如何解决提供以下我的代码的问题:
function App() {
return (
//BEM naming convention
<div className="app">
<div className="app_body">
<Router>
<Switch>
<Sidebar />
<Route path="/root/:roomId">
<Chat />
</Route>
<Route path="/">
<h1>Home screen</h1>
<Chat />
</Route>
</Switch>
</Router>
</div>
</div>
);
}
函数应用程序(){
返回(
//边界元命名约定
主屏幕
);
}
你能把你要执行的代码片段放出来吗?如果您能详细说明您期望的产量,我将不胜感激
据我所知,您可能需要在return()之前尝试添加以下内容:
如果使用类组件,请在return()
代码块之前的render()
方法中尝试此操作:
const { location } = this.props;
然后你可以继续使用位置你能把你要执行的代码片段放出来吗?如果您能详细说明您期望的产量,我将不胜感激
据我所知,您可能需要在return()之前尝试添加以下内容:
如果使用类组件,请在return()
代码块之前的render()
方法中尝试此操作:
const { location } = this.props;
然后您可以继续使用位置