Business Scenario
Hello talented developers!
Great job on creating and running your first React + Vite application!
Our client is now ready for us to start developing ShopKart – an E-commerce Web Application.
Before we start building features such as product listing, shopping cart, login and registration, we need to prepare a clean and scalable foundation for our project.
In this lab, we will configure the required libraries, define the ShopKart project structure, and create the basic pages and navigation that we will build upon in the upcoming labs.
Pre-Lab Preparation
Module:
1) React Introduction & JSX
2) Deep Dive into Component & Props
git pull origin branchNameGit Pull
Task 1:Install Required Dependencies
Open your ShopKart project in VS Code and Open the terminal
1
Install Bootstrap
2
npm install bootstrap
Install React Router DOM:
3
npm install react-router-dom
Install React Hook Form
4
npm install react-hook-form
Open package.json and verify that the dependencies have been added.
5
Task 2: Configure Bootstrap
Open : src/main.jsx
1
Add the Bootstrap CSS import at the top and Save the file
2
import 'bootstrap/dist/css/bootstrap.min.css';
Task 3 : Define the ShopKart Project Structure
Inside the src folder, create : components and pages folder
1
Task 4 : Create Basic Components
Inside components folder create : Navbar.jsx and Footer.jsx
1
For now, add a simple component to Navbar.jsx and Footer.jsx
2
import React from 'react'
export default function Navbar() {
return (
<nav>ShopKart Navbar</nav>
)
}
import React from 'react'
export default function Footer() {
return (
<footer>Footer</footer>
)
}
Task 5 : Create Basic ShopKart Pages
Inside pages folder create :
Create a simple content for each page
1
2
import React from 'react'
function Home() {
return (
<div>ShopKart Home</div>
)
}
export default Homeimport React from 'react'
function Products() {
return (
<div>ShopKart Products</div>
)
}
export default Productsimport React from 'react'
function Cart() {
return (
<div>Cart</div>
)
}
export default Cartimport React from 'react'
function Login() {
return (
<div>Login</div>
)
}
export default LoginTask 6 : Setup Basic Routing
Open main.jsx and import BrowserRouter
1
import { BrowserRouter } from "react-router-dom";
Wrap <App /> with BrowserRouter
2
import './index.css'
import App from './App.jsx'
import 'bootstrap/dist/css/bootstrap.min.css';
import { BrowserRouter } from 'react-router-dom';
createRoot(document.getElementById('root')).render(
<StrictMode>
<BrowserRouter>
<App />
</BrowserRouter>
</StrictMode>,
)Task 7 : Define Home and Products Routes
Open App.jsx and import :
1
import { Routes, Route } from "react-router-dom";
Import pages
2
import Home from "./pages/Home";
import Products from "./pages/Products";
Run the ShopKart Application
3
We are done with this lab. The latest source code has been uploaded to GitHub. You can access the latest commit using the link below:
Git Push
git push origin branchName
Great job!
ShopKart now has a clean and scalable foundation with the essential libraries, pages, components, and basic navigation in place.
Checkpoint
Next-Lab Preparation
Module:
1) React Introduction & JSX
2) Deep Dive into Component & Props