Open Terminal
npx create-react-app my-project
cd my-project
npm install -D tailwindcss
npx tailwindcss init
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./src/**/*.{js,jsx,ts,tsx}"],
theme: {
extend: {},
},
plugins: [],
};
@tailwind base;
@tailwind components;
@tailwind utilities;
npm run start
export default function App() {
return <h1 className="text-3xl font-bold underline">Hello world!</h1>;
}
npm i -D react-router-dom@latest
-To create an application with multiple page routes, let's first start with the file structure.
-Within the src folder, we'll create a folder named pages with several files:
src\pages:
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
import { BrowserRouter } from "react-router-dom";
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<React.StrictMode>
<BrowserRouter>
<App />
</BrowserRouter>
</React.StrictMode>
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
import { BrowserRouter } from "react-router-dom";
<BrowserRouter>
<App />
</BrowserRouter>
import { Route, Routes } from "react-router-dom";
import GovtJob from "./pages/GovtJob";
import PrivetJob from "./pages/PrivetJob";
import TeacherJob from "./pages/TeacherJob";
import ItJob from "./pages/ItJob";
import Home from "./components/Home";
import NavBar from "./components/NavBar";
import Contact from "./components/Contact";
import Blogs from "./components/Blogs";
import About from "./components/About";
function App() {
return (
<div className="max-w-screen-lg mx-auto">
<NavBar />
<Routes>
<Route path="/" element={<Home />} />
<Route path="/govtJob" element={<GovtJob />} />
<Route path="/privetJob" element={<PrivetJob />} />
<Route path="/teacherJob" element={<TeacherJob />} />
<Route path="/itJob" element={<ItJob />} />
{/* ============================================= */}
<Route path="about" element={<About />} />
<Route path="contact" element={<Contact />} />
<Route path="blogs" element={<Blogs />} />
</Routes>
</div>
);
}
export default App;
We define our
The nested
The Home component route does not have a path but has an index attribute. That specifies this route as the default route for the parent route, which is /.
Setting the path to * will act as a catch-all for any undefined URLs. This is great for a 404 error page.
The NavBar component has
The
Anytime we link to an internal path, we will use instead of .
The "NavBar route" is a shared component that inserts common content on all pages, such as a navigation menu.
import React from "react";
import { Outlet, Link } from "react-router-dom";
const NavBar = () => {
return (
<div>
<ul className="flex justify-center items-center gap-10 text-2xl pb-10">
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/about">About</Link>
</li>
<li>
<Link to="/contact">Contact</Link>
</li>
<li>
<Link to="/blogs">Blogs</Link>
</li>
</ul>
<Outlet />
</div>
);
};
export default NavBar;
import React from "react";
import { Link } from "react-router-dom";
const Home = () => {
return (
<div>
<h1 className="text-red-500 underline text-3xl text-center">
Home Page{" "}
</h1>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quibusdam et
voluptate rerum eaque adipisci soluta placeat ad temporibus, laborum
recusandae quas! Possimus eaque mollitia enim iste neque placeat omnis
veritatis.
</p>
<ul className="flex justify-center items-center gap-10 text-2xl pb-10 text-green-500">
<li>
<Link to="/govtJob">Govt Job</Link>
</li>
<li>
<Link to="/privetJob">Privet Job</Link>
</li>
<li>
<Link to="/teacherjob">Teacher Job</Link>
</li>
<li>
<Link to="/itJob">IT Job</Link>
</li>
</ul>
</div>
);
};
export default Home;