简体   繁体   English

如何使用按钮单击将ReactJS页面重定向到纯HTML页面?

[英]How to redirect ReactJS page to plain HTML page using button click?

I am wanting to have a button in my react project link to a simple html page I have put in the project. 我想在我的React项目链接中有一个按钮,该按钮指向我放入项目中的简单html页面。 However, anytime the main dashboard page loads, it immediately says cannot GET /Scanner.html. 但是,无论何时加载主仪表板页面,它都会立即显示无法GET /Scanner.html。

In my dashboard.js page that the website should default load to, I have this line of code: 在网站应默认加载到的我的dashboard.js页面中,我具有以下代码行:

          <Button color="primary" size="lg" onClick={window.location.href="Scanner.html"}>Scan Asset</Button>

All I want it to do is load the Scanner.html page that is right next to the dashboard.js page in the project itself when the button is clicked. 我要做的就是单击该按钮时,在项目本身中加载紧邻仪表板.js页面旁边的Scanner.html页面。 What am I doing wrong, or what do I need to add? 我做错了什么,或者我需要添加什么?

You need to provide a function as argument to the onClick prop. 您需要提供一个函数作为onClick属性的参数。 A simple way to do this: 一种简单的方法:

<Button color="primary" size="lg" onClick={() => window.location.href="Scanner.html"}>Scan Asset</Button>

Note the parentheses and the arrow. 请注意括号和箭头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM