Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
added routing
Browse files Browse the repository at this point in the history
  • Loading branch information
matt01y committed Mar 3, 2024
1 parent a3d9c96 commit 629bf15
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 8 deletions.
41 changes: 40 additions & 1 deletion frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.2"
},
"devDependencies": {
"@types/react": "^18.2.56",
Expand Down
33 changes: 31 additions & 2 deletions frontend/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import {createBrowserRouter, RouterProvider,} from "react-router-dom";
import './index.css'
import Root from './pages/root.tsx'
import ErrorPage from './pages/error.tsx'
import LoginScreen from "./pages/login/LoginScreen.tsx";
import HomeAdmin from "./pages/admin/HomeAdmin.tsx";
import HomeStudent from "./pages/student/HomeStudent.tsx";
import HomeTeacher from "./pages/teacher/HomeTeacher.tsx";

const router = createBrowserRouter([
{
path: "/",
element: <Root/>,
errorElement: <ErrorPage/>
},
{
path: "/login",
element: <LoginScreen/>
},
{
path: "/admin",
element: <HomeAdmin/>
},
{
path: "/student",
element: <HomeStudent/>
},
{
path: "/teacher",
element: <HomeTeacher/>
}
]);
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
<RouterProvider router={router}/>
</React.StrictMode>,
)
2 changes: 1 addition & 1 deletion frontend/src/pages/admin/HomeAdmin.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {JSX} from "react";

export function HomeAdmin(): JSX.Element {
export default function HomeAdmin(): JSX.Element {
return (
<>Homescreen for an admin</>
)
Expand Down
17 changes: 17 additions & 0 deletions frontend/src/pages/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useRouteError } from "react-router-dom";
import {JSX} from 'react';

export default function ErrorPage(): JSX.Element {
const error = useRouteError();
console.error(error);

return (
<div id="error-page">
<h1>Oops!</h1>
<p>Sorry, an unexpected error has occurred.</p>
<p>
<i>{error.statusText || error.message}</i>
</p>
</div>
);
}
2 changes: 1 addition & 1 deletion frontend/src/pages/login/LoginScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {JSX} from "react";

export function LoginScreen(): JSX.Element {
export default function LoginScreen(): JSX.Element {
return (
<>Login screen</>
)
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/pages/root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {JSX} from "react";
import {Link} from "react-router-dom";

export default function Root(): JSX.Element {
// TODO: logic to send user to /login or
return (
<>
<>Redirecting ...</>
<Link to={`/login`}>goto login page</Link>
</>
)
}
2 changes: 1 addition & 1 deletion frontend/src/pages/student/HomeStudent.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {JSX} from "react";

export function HomeStudent(): JSX.Element {
export default function HomeStudent(): JSX.Element {
return (
<>Homescreen for a student</>
)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/teacher/HomeTeacher.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {JSX} from "react";

export function HomeTeacher(): JSX.Element {
export default function HomeTeacher(): JSX.Element {
return (
<>Homescreen for a teacher</>
)
Expand Down

0 comments on commit 629bf15

Please sign in to comment.