1

I am wanting to have a button in my react project link to a simple html page I have put in the project. However, anytime the main dashboard page loads, it immediately says cannot GET /Scanner.html.

In my dashboard.js page that the website should default load to, I have this line of code:

          <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. What am I doing wrong, or what do I need to add?

1
  • <button onClick={() => {window.location.href="google.co.uk"}}>redirect</button> Commented Apr 2, 2018 at 17:26

1 Answer 1

2

You need to provide a function as argument to the onClick prop. 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.

Sign up to request clarification or add additional context in comments.

3 Comments

That allowed the dashboard page to load without any issue, but whenever I click on the button, it still says cannot GET /Scanner.html. Even though the file is right next to the dashboard.js file. Am I thinking about this wrong? I appreciate your help!
Then it's a path issue. The HTML file needs to be in the same location as the HTML file where your Javascript file is embedded in, not the location of the JS file
I will figure out the exact path then. Thank you very much!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.