I am new with React JS so I am sorry if this problem seems trivial.
I have set up a <Switch> along with a number of Routes in App.js to redirect and link components together. The first <Redirect> from App.js goes to ComponentA where when a div is clicked, it should go to ComponentB, but that is not the case. After some fiddling, I could get ComponentB to render but it was ALONG with ComponentA, and now with more changes, nothing shows up except the header .../componentB.
App.js
import { ComponentA, ComponentB } from './components/Component.js';
import { BrowserRouter as Router, Route, Redirect, Switch} from 'react-router-dom';
function App() {
const [isLoggedIn, setIsLoggedIn] = useState(false);
return (
<div>
<Router exact path="/">
<Switch>
<Route exact path="/componentA" component={ComponentA}/>
<Route exact path="/componentB" component={ComponentB}/>
<Route exact path="/componentC" component={ComponentC}/>
</Switch>
{isLoggedIn ? <Redirect to="/componentA"/> : <Redirect to="/componentC"/>}
// componentC is irrelevant to the question
</Router>
</div>
);
}
ComponentA
import { BrowserRouter as Router, Route, Redirect, Switch} from 'react-router-dom';
function ComponentA() {
return (
<div>
<Router exact path="/">
// ... code
<Link exact to="/componentB">
<div></div>
</Link>
</Router>
</div>
);
}
ComponentB (in the same file as ComponentA)
function ComponentB() {
return (
<div>Welcome to ComponentB</div>
);
}