The url is updated whenever a link in the navbar is clicked, but the components relating to specific end-points are not rendered on the browser.
So for example, when the Profile button is clicked, the url is changed to the "/profile"
, but the profile component is never displayed.
I've included NavBar
and App
file code snippets.
I need assistance determining what is causing the problem and resolving it.
NavBar.js
import React from "react";
import { Link } from "react-router-dom";
const NavBar = () => {
return (
<nav>
<div className="nav-wrapper white">
<Link to="/" className="brand-logo left">Instagram</Link>
<ul id="nav-mobile" className="right hide-on-med-and-down">
<li><Link to="/signin">Signin</Link></li>
<li><Link to="/signup">Signup</Link></li>
<li><Link to="/profile">Profile</Link></li>
</ul>
</div>
</nav>
)
}
export default NavBar;
App.js
import React from "react";
import { BrowserRouter, Route } from "react-router-dom";
import './App.css';
import NavBar from "./components/Navbar"
import Home from './components/screens/Home';
import Signup from './components/screens/Signup';
import Profile from './components/screens/Profile';
import Login from './components/screens/Login';
function App() {
return (
<BrowserRouter>
<NavBar />
<Route exact path="/" component={Home} />
<Route path="/signin" component={Login} />
<Route path="/signup" component={Signup} />
<Route path="/profile" component={Profile} />
</BrowserRouter>
);
}
export default App;
Currently output:
Expected output:
---EDIT---
My main concern is that when I click the button, the url changes but the content is not rendered. When I refresh the url, the new component is rendered.
react-router-dom version: 5.1.2
Each component Home, Login, Signup, and Profile display the respective component name in h1.
Home.js
import React from "react";
const Home = () =>{
return(
<h1>home</h1>
)
}
export default Home
Profile.js
import React from "react";
const Profile = () =>{
return(
<h1>Profile</h1>
)
}
export default Profile