在 React.js 中单击按钮时重新加载页面

问题描述 投票:0回答:1

我想在单击按钮时重新加载反应页面, 这就是我想做的

<IconButton onClick={() => window.location.reload()}>
    <CachedIcon  
       style={{ color: "black", fontSize: "2rem" }}
      />
</IconButton>

但是我在这里遇到了错误

无法读取未定义的属性(读取“位置”)类型错误: 无法读取未定义的属性(读取“位置”)

即使在 console.log(window) 上我也遇到 undefined

所以我无法实现重新加载按钮,有人可以给我吗?

ps:我在这里使用 mui 图标

reactjs react-router
1个回答
0
投票

您是否使用框架,例如下一个.JS?如果您是,并且没有将组件的文件标记为“使用客户端”,则它不会在浏览器中运行,因此没有窗口。

© www.soinside.com 2019 - 2024. All rights reserved.