This repo contains the code for EPAI's React based website in the "main" branch. When compiled the code is deployed to the "gh-pages" branch as that is where the code is hosted from.
Code snippets are a snapshot of a previous version of the codebase. Current files may have additional pages/lines.
In order to run this site locally for editing or testing purposes you can do the following:
- Pull the GitHub Repository to your local machine
- Open your local instance of this repo and Run
npm installin your terminal to install the necessary npm packages for the site - You can now run
npm startto run the site on your localhost. A window should automatically open for this. - You're now free to edit the website and view live changes on your local instance.
Before making edits ensure you have pulled the current version of the website to avoid conflicts if someone else has made changes. After making edits ensure that you push to the repo. Either in a separate branch to be merged with the main or directly to main if you only made small tweaks.
- When you are happy with your changes you can run
npm run deployto deploy the site to the GitHub Pages deployment.
- Start by duplicating the
src/template.jsxfile and renaming it to a descriptive name. Its contents are approximately as follows:
import React from "react";
import panel from "../../images/ethics_panel_page.png"; // Image Import
export default function template() {
return (
<div className="about">
<div class="container">
<div class="my-5">
<div class="container">
<h1>Template</h1> // Example Title
</div>
<hr/>
<p style={{'textAlign': 'center'}}>Centered Body Text</p>
<img alt="" class="rounded" style={{'width':'100%'}} src={panel}/> // Image Usage
</div>
</div>
</div>
);
}- Change
templatein line 4 to an equally descriptive name for this page. This will also need to be added to two other files. For this example whenever you see "template" replace that with the name you put here. - Edit
src/index.jsto add a line that says:export { default as template } from "./template"; - Edit
./index,jsas follows:
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import * as serviceWorker from "./serviceWorker";
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
import {
Navigation,
Footer,
Home,
About,
Joinus,
Projects,
Events,
RaiSoden,
Dullerud,
Fair2021,
Info2021,
Info2022,
Panel2021,
News,
ReadingGroup,
ScrollToTop,
+ template,
} from "./components";
ReactDOM.render(
<Router>
<Navigation />
<p style={{"padding-top": "50px"}}></p>
<ScrollToTop />
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
<Route path="/joinus" element={<Joinus />} />
<Route path="/projects" element={<Projects />} />
<Route path="/events" element={<Events />} />
<Route path="/raisoden" element={<RaiSoden />} />
<Route path="/dullerud" element={<Dullerud />} />
<Route path="/fair2021" element={<Fair2021 />} />
<Route path="/info2021" element={<Info2021 />} />
<Route path="/info2022" element={<Info2022 />} />
<Route path="/panel2021" element={<Panel2021 />} />
<Route path="/news" element={<News />} />
<Route path="/ReadingGroup" element={<ReadingGroup />} />
// Where the path represents the routing for how to access the page.
+ <Route path="/template" element={<template />} />
</Routes>
<Footer />
</Router>,
document.getElementById("root")
);
serviceWorker.unregister();Now the file is created and will be accessible via the chosen path after deployment.
This can be linked to from another page or the NavBar using NavLink.
- The bulk of the site's content can be found within
src/componentswithsrc/template.jsxbeing a great starting point for building out new pages - When you run
npm run deploythe deployment will be compiled into thegh-pagesbranch which is where the site is being hosted from. This allows us to continue using the main branch for our primary codebase - While React is typically used for creating single page websites, you can make use of
react-router-domto allow pseudo multi-page websites as we have done here. This can result in some complications with GitHub trying to load from alternative repositories when using paths to access these pages. This can be fixed by creating a 404.html file to redirect these 404 errors back to your main repository.