Using React Router
Sat Jun 18 2022 07:22:23 GMT+0000 (Coordinated Universal Time)
Saved by
@patdevwork
npm install react-router-dom // install on your project.. can add specific version by adding @6 at the end
// edit the index.js and import react router
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
// import the location of the components
import { App, About, Contact } from "./App";
import {BrowserRouter, Route, Routes} from "react-router-dom"
ReactDOM.render(
<BrowserRouter>
// Use Routes to set the correct route of each component
<Routes>
<Route path="/" element={<App />} /> // Route Identify the component and the link you want to use or path to use.
<Route path="/about" element={<About />} />
<Route path="/contact" element={<Contact />} />
</Routes>
</BrowserRouter>,
document.getElementById("root")
);
// Create links
content_copyCOPY
Comments