0

My issue is when I try to use "Link" in my Nav.js, I get an Error of

enter image description here

Here is my App.js

Here is my Nav.js

Here is my Orders.js

[Here is my Products.js4

3
  • try putting <div className="App"><Router></Router></div> inside your div in App.js Commented Nov 15, 2020 at 15:16
  • return ( <div className="App"> <Router> <Nav /> <Switch> <Route path="/" exact component={Home} /> <Route path="/orders" component={Orders} /> <Route path="/products" component={Products} /> </Switch> </Router> </div> ); Commented Nov 15, 2020 at 15:24
  • Did you mean like this? -This still had the same error Commented Nov 15, 2020 at 15:24

2 Answers 2

1

The first error that may occurs will come from your Home function component:-

  • in App.js:- edit your const Home to this (it should be wrap in return):-
const Home = () => {
  return (
    <div>
      <h1>Homepage</h1>
    </div>
  )
}

Other than that everything will works just fine tho. Anyhow, you can see it here on this sandbox to compare it with your current code.

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

4 Comments

Thank you for the sandbox. My code matches up... Am I missing something? Like a npm install or something?
Sometimes it could happen because of the react, react-dom and router-router-dom not up to date. Try see the version that you have now and get it up to the latest one
Okay... I give up trying to understand why. In the end, I just copy and paste your code and it works. Thank you!
Glad I can help
1

use <BrowserRouter> in Nav component

2 Comments

Wait.... A new issue has come from that. Now when I click on the link. It changes the URL to /whatever but it does not change the screen. I would need to actually manually refresh the page.
You need to specify the attribute exact for your indexRoute '/' <Route exact path="/" component={Home} /> in App.js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.