我已经向React页面发出了请求,我需要从请求中获取标头。
我通过URL调用页面:
http:// localhost / dashboard
然后设置标头,例如authcode = 1234。
然后,我使用以下路线加载页面:
<Route path="dashboard" name="dashboard" component={Dashboard} onEnter={requireAuth}></Route>
是否有类似this.props.header的东西,我可以在页面构造函数中调用?
您无法通过javascript发送http请求而无法获取当前页面标题。有关更多信息,请参见此答案。
在您的服务器上添加一个虚拟的api网址,并在页面加载后点击它,然后就可以获取标题了。
class App extends React.Component{ //some code componentDidMount(){ fetch(Some_API).then(response=>{ console.log(response.headers) }) } //some code }