English Soccer News gives you the latest news about soccer match in Europe and UK. Enjoy!

✅ Steps to Build a Static Website Using React

Build a fully static website using just the React framework. Since React is primarily a Single Page Application (SPA) framework, it doesn’t generate static HTML pages by default like traditional static site generators (e.g., Next.js or Hugo). However, you can still create a static website using React + Vite or React + Create React App (CRA) by following these steps:


Steps to Build a Static Website Using React

1️⃣ Set Up a React Project

If you haven't already created a React project, you can use Vite for better performance:

npm create vite@latest my-static-site --template react
cd my-static-site
npm install
npm run dev

Or, if you prefer Create React App (CRA):

npx create-react-app my-static-site
cd my-static-site
npm start

2️⃣ Create Your Static Pages Using Components

You can create multiple static pages using React components inside the src/components/ folder.

Example:

  • src/components/Home.jsx
  • src/components/About.jsx
  • src/components/Contact.jsx

Example: Home Page (Home.jsx)

function Home() {
  return (
    <div>
      <h1>Welcome to My Static React Website</h1>
      <p>This is a simple static website built using React.</p>
    </div>
  );
}

export default Home;

Example: About Page (About.jsx)

function About() {
  return (
    <div>
      <h1>About Us</h1>
      <p>We are a team of developers building awesome React sites.</p>
    </div>
  );
}

export default About;

3️⃣ Use React Router for Page Navigation

Since React is a SPA (Single Page Application), you need React Router to navigate between different pages.

👉 Install React Router:

npm install react-router-dom

👉 Update App.jsx to include routing:

import { BrowserRouter as Router, Routes, Route, Link } from 'react-router-dom';
import Home from './components/Home';
import About from './components/About';

function App() {
  return (
    <Router>
      <nav>
        <Link to="/">Home</Link> | <Link to="/about">About</Link>
      </nav>
      <Routes>
        <Route path="/" element={<Home />} />
        <Route path="/about" element={<About />} />
      </Routes>
    </Router>
  );
}

export default App;

4️⃣ Build and Export as Static Files

Once your React website is ready, you need to build it as a static site.

👉 Run the Build Command

npm run build

This will generate a dist/ folder (for Vite) or build/ folder (for CRA) containing static HTML, CSS, and JS files.


5️⃣ Deploy Your Static Website

Now that you have the static files, you can host them on any static hosting service like:

Hosting Service Deployment Command / Steps
GitHub Pages npm install gh-pages → Add "homepage": "https://yourusername.github.io/repo-name" in package.jsonnpm run buildnpm run deploy
Netlify Drag & drop dist/ or build/ into Netlify
Vercel Install Vercel CLIvercel
Cloudflare Pages Connect GitHub Repo or Upload build/ manually
Firebase Hosting firebase deploy (after Firebase setup)

🎯 Conclusion

Build a fully static website using React! 🚀 However:

  • If your website is purely static (no user interactions, no API calls, just HTML/CSS), a static site generator like Next.js or Astro might be a better option.
  • But if you want a static site with React’s component-based structure and interactivity, using React + React Router is a great approach.


0 Comment: