To start a new project after cloning an empty repo, run the following command:
npm create vite@latest .
npm install
npm run dev- Create the
componentsandpagesfolders inside thesrcdirectory:
project-root/
├── src/
│ ├── components/
│ ├── pages/
│ ├── App.jsx
│ ├── index.css
│ ├── main.jsx
│ └── ...
├── package.json
├── vite.config.js
└── ...
-
Remove all content inside
App.jsxand deleteApp.css. Also, remove theimport './App.css';line fromApp.jsx. -
Clear all CSS lines inside
index.css, as we will be using Tailwind CSS.
To manage navigation between different pages, install the react-router-dom package:
npm install react-router-domOnce installed, update the main App.js (or App.tsx if using TypeScript) file to include routing logic:
import { BrowserRouter, Routes, Route } from "react-router-dom";
import Layout from "./components/Layout";
import HomePage from "./pages/HomePage";
function App() {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<Layout />}>
<Route index element={<HomePage />} />
</Route>
</Routes>
</BrowserRouter>
);
}
export default App;BrowserRouter: Wraps the entire application, enabling routing capabilities.Routes: Container for all route definitions.Route path="/" element={<Layout />}: Defines the base route (/) that loads theLayoutcomponent.Route index element={<HomePage />}: EnsuresHomePageis the default child ofLayoutat the root path.
The Layout component acts as a wrapper for pages, containing shared UI elements like the header and footer.
import { Outlet } from "react-router-dom";
import Header from "./Header";
import Footer from "./Footer";
import Providers from "./Providers";
const Layout = () => {
return (
<Providers>
<Header />
<Outlet />
<Footer />
</Providers>
);
};
export default Layout;Providers: Wrapper for global providers (Theme, Auth, Redux/Zustand providers).Header: A global navigation bar.Outlet: Dynamically injects pages based on the route.Footer: A common footer for all pages.
To set up Tailwind CSS, install the required dependencies:
npm install tailwindcss @tailwindcss/viteAdd the following line to src/index.css:
@import "tailwindcss";Modify your vite.config.js file to include Tailwind CSS:
import path from "path";
import tailwindcss from "@tailwindcss/vite";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
// https://vite.dev/config/
export default defineConfig({
plugins: [react(), tailwindcss()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
});Create a jsconfig.json file in the root of the project and add the following configuration:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/_": ["src/_"]
}
}
}run the following command
npx shadcn@latest initBy structuring the project this way, we:
✅ Centralize layout components like the header and footer.
✅ Use Outlet to dynamically render pages.
✅ Improve maintainability and scalability of the application.
✅ Enhance UI styling with Tailwind CSS and ShadCN.
This setup provides a strong foundation for adding more routes and features as the project grows.