diff --git a/frontend/src/components/App/index.js b/frontend/src/components/App/index.js index 0fde1b02..9d803d8b 100644 --- a/frontend/src/components/App/index.js +++ b/frontend/src/components/App/index.js @@ -1,5 +1,5 @@ import React from 'react'; -import {BrowserRouter as Router, Route} from 'react-router-dom'; +import {BrowserRouter as Router, Switch, Route} from 'react-router-dom'; import { AuthProvider, PrivateRoute } from '../Auth'; import { AuthUtilsConsumer } from '../AuthUtils'; @@ -7,6 +7,7 @@ import LandingPage from '../Landing'; import SignInPage from '../SignIn' import ViewActivitiesPage from '../ViewActivities'; import ViewTripsPage from '../ViewTrips'; +import { ErrorPageNotFound } from '../Errors'; import * as ROUTES from '../../constants/routes'; /** @@ -20,10 +21,14 @@ class App extends React.Component {
- - - - + + + + + + {/* The ErrorNotFound component MUST be at the bottom of the Router! */} + +
diff --git a/frontend/src/components/Errors/ErrorPageNotFound.js b/frontend/src/components/Errors/ErrorPageNotFound.js new file mode 100644 index 00000000..8ff00568 --- /dev/null +++ b/frontend/src/components/Errors/ErrorPageNotFound.js @@ -0,0 +1,21 @@ +import React from 'react'; +import GoToLandingButton from './GoToLandingButton.js'; + +/** + * Error component displayed when the user attempts to navigate to a page of the + * website that does not exist. + */ +class ErrorPageNotFound extends React.Component { + /** @inheritdoc */ + render() { + return ( +
+

Error 404 Page Not Found

+

Oops, looks like the page you were looking for doesn't exist.

+ +
+ ); + } +}; + +export default ErrorPageNotFound; diff --git a/frontend/src/components/Errors/GoToLandingButton.js b/frontend/src/components/Errors/GoToLandingButton.js new file mode 100644 index 00000000..144fa6cd --- /dev/null +++ b/frontend/src/components/Errors/GoToLandingButton.js @@ -0,0 +1,26 @@ +import React from 'react'; +import { useHistory } from 'react-router-dom'; + +import Button from 'react-bootstrap/Button'; + +import { LANDING } from '../../constants/routes.js'; + +/** + * Component that redirects the user back to the landing page when they + * encounter a 404 error. + */ +const GoToLandingButton = () => { + const history = useHistory(); + + function goToLanding() { + history.push(LANDING); + } + + return ( + + ); +} + +export default GoToLandingButton; diff --git a/frontend/src/components/Errors/index.js b/frontend/src/components/Errors/index.js new file mode 100644 index 00000000..b1ac1f35 --- /dev/null +++ b/frontend/src/components/Errors/index.js @@ -0,0 +1,5 @@ +import ErrorPageNotFound from './ErrorPageNotFound.js'; + +export { + ErrorPageNotFound +}