Recently I've started learning ReactJS and I do not look forward to making one Page website so I learned about react-router
and this is my way of doing to it.
App.js
import React, { Component } from "react";
import "babel-polyfill";
import Navbar from "./Components/MenuNavbar";
import Footer from "./Components/Bottom";
import Home from "./Components/Home";
import About from "./Components/About";
import Contact from "./Components/Contact";
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
import Products from "./Components/Products";
import { CircleArrow as ScrollUpButton } from "react-scroll-up-button";
// import Topbar from "./Components/Topbar";
class App extends Component {
render() {
return (
<div className="App">
<Router>
<React.Fragment>
<Navbar />
<Switch>
<Route exact path="/" component={Home} />
<Route exact path="/products" component={Products} />
<Route exact path="/about" component={About} />
<Route exact path="/contact" component={Contact} />
</Switch>
<ScrollUpButton />
<Footer />
</React.Fragment>
</Router>
</div>
);
}
}
export default App;
In my other Components, I wrap parent in a div
as learned in some tutorials, like this:
render() {
return (
<div id="products">
<ProductsHero />
<ProductsCashew />
<ProductsAlmonds />
</div>
);
}
Is this the best practice? If not how can I improve? Shall I wrap every child in React.Fragment
instead of div
? If so why?