I am learning React.js. I need to know how can I display more than one component in App.js. I have 2 pages which are Home.js and About.js
.
After run the code Just click on About us then you will get only About Page text. But I have About Team and About content too in the About.js file. That is not displaying. I import the
import { About, AboutTeam, AboutContent } from "./Pages/About";
but never use till now because I don't know where should I add AboutTeam, AboutContent
. Please check my App.js
file. I just need when the user clicks on About us then It will display all the components which I have in About.js
.
I added example here https://codesandbox.io/s/happy-almeida-t6q7w?file=/src/App.js
I am getting
This is my expected output
One more doubt, I am using the below code so is this code is the correct way to use?
Would you help me out with this?
Home.js
import React from 'react';
import 'bootstrap/dist/css/bootstrap.min.css';
import './css/Style.css';
const Home=()=>{
return(
<div className="">
<h2>Home page</h2>
</div>
);
}
export default Home;
About.js
import React from 'react';
import 'bootstrap/dist/css/bootstrap.min.css';
import './css/Style.css';
const About=()=>{
return(
<div className="">
<h2>About page</h2>
</div>
);
}
const AboutTeam = () => {
return (
<div className="">
<h2>About Team dummy text</h2>
</div>
);
};
const AboutContent = () => {
return (
<div className="">
<h2>About content dummy text</h2>
</div>
);
};
export { About, AboutTeam, AboutContent };
App.js
import React from 'react';
import 'bootstrap/dist/css/bootstrap.min.css';
import './css/Style.css';
import HeaderMenu from './components/Header';
import Home from './pages/Home';
import { About, AboutTeam, AboutContent } from "./Pages/About";
import Footer from './components/Footer';
import { BrowserRouter, Route, Switch } from 'react-router-dom';
const App=()=>{
return(
<BrowserRouter>
<HeaderMenu />
<div className="">
<Switch>
<Route path="/" exact component={Home} />
<Route path="/about" component={About} />
</Switch>
</div>
<Footer />
</BrowserRouter>
);
}
export default App;
Index.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import * as serviceWorker from './serviceWorker';
ReactDOM.render(<App />,document.getElementById('root'));
serviceWorker.unregister();