I have got an issue with React Router, when i am running the app the main page shows but the others not render, I am using some library for the Navigation bar that called react-responsive-animate-navbar, the Nav bar is working properly and the URL is change when i click but the component that i specify for the path/url is not render. I tried a couple of solutions that i found on stackoverflow and github and none of them work.
Code:
App.js
import React, { useState } from "react";
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
import NavigationBar from "../NavigationBar/NavigationBar";
import Menu from "../Menu/Menu";
import Login from "../Login/Login";
import UpdateUser from "../UpdateUser/UpdateUser";
const App = () => {
const [token, setToken] = useState(1);
return (
<Router>
<NavigationBar token={token} />
<Switch>
<Route exact path="/" component={token >= 0 ? Menu : () => <Login token={token} setToken={setToken}/>} />
<Route path="/update" component={() => <UpdateUser />} />
</Switch>
</Router>
);
};
NavigationBar
import React from "react";
import { ReactNavbar } from "react-responsive-animate-navbar";
import "./NavigationBar.css";
const NavigationBar = ({ token }) => {
return (
<ReactNavbar
color="#000"
logo="../../styles/images/logo.png"
menu={[
{ name: "דף הבית", to: "/" },
{ name: "מדריך", to: "/guide" },
{ name: "עדכון משתמש", to: "/update" },
{ name: "התנתק", to: "/contact" },
]}
/>
);
};
export default NavigationBar;
UPDATE:
I figure out that when i change the url and refresh the page is rendered, otherwise nothing happend on clicking and the url is only changing. How can i make it render without the need to refresh ?
Thank you all in advance !