FSD Lab Program-17
FSD Lab Program-17
17. Create a react application for an online store which consist of registration,
login, product information pages and implement routing to navigate through these
pages.
cd online-store
npm start
import './App.css';
function App() {
return (
<Router>
<div className="online-store">
<nav>
<Link to="/">Home</Link>
<Link to="/register">Register</Link>
<Link to="/login">Login</Link>
<Link to="/products">Products</Link>
</nav>
<Routes>
</Routes>
</div>
</Router>
);
function Home() {
return (
<div>
</div>
);
function Register() {
const [user, setUser] = useState({ name: "", email: "", password: "" });
};
e.preventDefault();
alert("Registration Successful!");
};
return (
<div>
<h2>Register</h2>
<form onSubmit={handleSubmit}>
<button type="submit">Register</button>
</form>
</div>
);
function Login() {
};
e.preventDefault();
alert("Login Successful!");
};
return (
<div>
<h2>Login</h2>
<form onSubmit={handleSubmit}>
<button type="submit">Login</button>
</form>
</div>
);
const products = [
];
function Products() {
return (
<div>
<h2>Our Products</h2>
<ul>
{products.map((product) => (
<li key={product.id}>
<strong>{product.name}</strong> - {product.price}
</li>
))}
</ul>
</div>
);
.online-store {
text-align: center;
nav {
margin: 20px;
nav a {
margin: 10px;
padding: 10px;
text-decoration: none;
background-color: #007bff;
color: white;
border-radius: 5px;
nav a:hover {
background-color: #0056b3;
input {
margin: 5px;
padding: 10px;
width: 200px;
button {
padding: 10px;
font-size: 16px;
cursor: pointer;
background-color: #28a745;
color: white;
border: none;
border-radius: 5px;
button:hover {
background-color: #218838;
}
ul {
list-style: none;
padding: 0;
li {
margin: 10px 0;
padding: 10px;
border-radius: 5px;
background-color: #f9f9f9;
Explanation:
npm start
3. Click Home, Register, Login, and Products to navigate through the application.
4. Test the registration and login forms by filling in details and clicking submit.