Skip to content

Commit

Permalink
feat: add routing for home, login and notFound page
Browse files Browse the repository at this point in the history
  • Loading branch information
SplitCode committed Oct 2, 2024
1 parent bd8c461 commit 969f144
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 21 deletions.
25 changes: 6 additions & 19 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
import logo from './logo.svg';
import './App.css';
import { Outlet } from 'react-router-dom';
import Header from './components/Header';

const App = () => (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit
<code>src/App.js</code>
and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
<>
<Header />
<Outlet />
</>
);

export default App;
7 changes: 7 additions & 0 deletions frontend/src/components/Header.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const Header = () => (
<div>
Header
</div>
);

export default Header;
5 changes: 3 additions & 2 deletions frontend/src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import { RouterProvider } from 'react-router-dom';
import router from './router/router';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
<RouterProvider router={router} />
</React.StrictMode>,
);
8 changes: 8 additions & 0 deletions frontend/src/pages/Home.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const Home = () => (
<div>
<h1>Home Page</h1>
<p>Welcome to the Home Page!</p>
</div>
);

export default Home;
5 changes: 5 additions & 0 deletions frontend/src/pages/Login.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const Login = () => (
<h1>Login Page</h1>
);

export default Login;
8 changes: 8 additions & 0 deletions frontend/src/pages/NotFound.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const NotFound = () => (
<div>
<h1>404 - Page Not Found</h1>
<p>The page you are looking for does not exist.</p>
</div>
);

export default NotFound;
28 changes: 28 additions & 0 deletions frontend/src/router/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { createBrowserRouter } from 'react-router-dom';
import Home from '../pages/Home';
import Login from '../pages/Login';
import NotFound from '../pages/NotFound';
import App from '../App';

const router = createBrowserRouter([
{
path: '/',
element: <App />,
children: [
{
index: true,
element: <Home />,
},
{
path: 'login',
element: <Login />,
},
{
path: '*',
element: <NotFound />,
},
],
},
]);

export default router;

0 comments on commit 969f144

Please sign in to comment.