Everything compiles successfully but my local host is a blank page, I have no issues but I am wondering why when i run npm start and it takes me to a new live page the page is blank but my home.jsx has the correct code that I used from my home.html code. If anyone could help me figure out why my page is blank that would be great. Thank you!
App.js
import React from 'react';
import Home from './components/home/home.jsx';
function App() {
return (
<div className="App">
<Home />
</div>
);
}
export default App;
home.jsx
import React from 'react';
import { Link } from 'react-router-dom';
import './home.css';
function Home() {
return (
<div>
<nav className="navbar">
<ul className="nav-list">
<li><Link to="/home">Home</Link></li>
<li><Link to="/marketplace">Marketplace</Link></li>
<li><Link to="/settings">Settings</Link></li>
<li><Link to="/profile">Profile</Link></li>
<li><Link to="/chat">Chat</Link></li>
</ul>
<div className="rightNav">
<input type="text" name="search" id="search" placeholder="Search" />
<button className="btn btn-sm">Search</button>
</div>
</nav>
<main>
<section className="new-items">
<h2>New Items</h2>
<Link to="/marketplace" className="button-link">
<button>Browse Items</button>
</Link>
</section>
<section className="my-saved">
<h2>My Saved</h2>
<button>View Saved</button>
</section>
</main>
</div>
);
}
export default Home;
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
2
Answers
There are 2 things you can try:
That’s because you are using
<Link></Link>
tag in your home component but you have not yet set up routes in your App.jsx. If you would check your console, you will see all the errors.You can set up your App.js like this:
Also for the Home component, the standard practice is to use
'/'
for the path. This way we make sure home is the first thing to show up when your app renders.I noticed that you have included the Navbar in your home component. Instead, you should have made a new Navbar component which will only include the Navbar, and put it in App.jsx before defining routes. This way, the Navbar remains the same all across the App.
Something like this:
Navbar.jsx
App.jsx
home.jsx
Navbar will always be the same so we don’t have to include it in every page, instead put it at the top of your router. All the pages inside router, will render beneath the Navbar. If you want you can make a Footer component as well and put it at the bottom. Like this:
App.jsx