Skip to content

Commit 36283f4

Browse files
feat: routing
1 parent ce58974 commit 36283f4

File tree

9 files changed

+195
-32
lines changed

9 files changed

+195
-32
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from "react";
2+
3+
export const BiographyPage: React.SFC = () => {
4+
return <h1>BIOGRAPHY PAGE</h1>;
5+
};

frontend/containers/LandingPage/index.tsx

+28-23
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React from "react";
22
import { Image, Span, GreetingsBox } from "./style";
33
import rocketLaunch from "../../icons/rocketLaunch.png";
44
import { useLandingPageContext } from "../../contexts/LandingPageContext";
5+
import { Layout } from "../../components/Layout";
6+
import { Header } from "../../components/Header";
57
const Modal = React.lazy(() => import("./Modal"));
68

79
export const LandingPage: React.FC = () => {
@@ -13,33 +15,36 @@ export const LandingPage: React.FC = () => {
1315
displayTipEditionModal,
1416
displayTipsModal,
1517
removeTip,
16-
editTip
18+
editTip,
1719
} = useLandingPageContext();
1820

1921
return (
2022
<>
21-
<React.Suspense fallback={"loading..."}>
22-
{!!state.modal && (
23-
<Modal
24-
state={state}
25-
hideTipsModal={hideTipsModal}
26-
addTip={addTip}
27-
displayTipAdditionModal={displayTipAdditionModal}
28-
displayTipEditionModal={displayTipEditionModal}
29-
displayTipsModal={displayTipsModal}
30-
removeTip={removeTip}
31-
editTip={editTip}
32-
/>
33-
)}
34-
</React.Suspense>
35-
<GreetingsBox data-testid="greetingsBox">
36-
<Span data-testid="span">
37-
The install worked successfully! Congratulations!
38-
</Span>
39-
<br />
40-
<Span data-testid="span">Now go build something great 😃!</Span>
41-
</GreetingsBox>
42-
<Image src={rocketLaunch} alt={"Rocket being launched"} />
23+
<Header />
24+
<Layout>
25+
<React.Suspense fallback={"loading..."}>
26+
{!!state.modal && (
27+
<Modal
28+
state={state}
29+
hideTipsModal={hideTipsModal}
30+
addTip={addTip}
31+
displayTipAdditionModal={displayTipAdditionModal}
32+
displayTipEditionModal={displayTipEditionModal}
33+
displayTipsModal={displayTipsModal}
34+
removeTip={removeTip}
35+
editTip={editTip}
36+
/>
37+
)}
38+
</React.Suspense>
39+
<GreetingsBox data-testid="greetingsBox">
40+
<Span data-testid="span">
41+
The install worked successfully! Congratulations!
42+
</Span>
43+
<br />
44+
<Span data-testid="span">Now go build something great 😃!</Span>
45+
</GreetingsBox>
46+
<Image src={rocketLaunch} alt={"Rocket being launched"} />
47+
</Layout>
4348
</>
4449
);
4550
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from "react";
2+
3+
export const PublicationPage: React.SFC = () => {
4+
return <h1>PUBLICATION PAGE</h1>;
5+
};

frontend/containers/Routes/index.tsx

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from "react";
2+
import { Switch, Route } from "react-router-dom";
3+
import { LandingPage } from "../LandingPage";
4+
import { BiographyPage } from "../BiographyPage";
5+
import { ROUTES } from "../../routes";
6+
import { PublicationPage } from "../PublicationPage";
7+
8+
export const Routes = () => {
9+
return (
10+
<Switch>
11+
<Route path={ROUTES.LANDING_PAGE} exact>
12+
<LandingPage />
13+
</Route>
14+
<Route path={ROUTES.BIOGRAPHY_PAGE} exact>
15+
<BiographyPage />
16+
</Route>
17+
<Route path={ROUTES.PUBLICATION_PAGE} exact>
18+
<PublicationPage />
19+
</Route>
20+
</Switch>
21+
);
22+
};

frontend/index.tsx

+6-8
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import * as React from "react";
22
import { render } from "react-dom";
33
import { createGlobalStyle, ThemeProvider } from "styled-components";
44
import { theme, Theme } from "./utils/theme";
5-
import { Header } from "./components/Header";
6-
import { Layout } from "./components/Layout";
75
import { LandingPageProvider } from "./contexts/LandingPageContext";
86
import { register } from "./serviceWorker";
9-
import { LandingPage } from "./containers/LandingPage";
7+
import { BrowserRouter } from "react-router-dom";
8+
import { Routes } from "./containers/Routes";
109

1110
const GlobalStyle = createGlobalStyle<{ theme: Theme }>`
1211
html {
@@ -15,7 +14,7 @@ const GlobalStyle = createGlobalStyle<{ theme: Theme }>`
1514
overflow-x: hidden;
1615
1716
body {
18-
${props => props.theme.fontFamily}
17+
${(props) => props.theme.fontFamily}
1918
margin: 0;
2019
height: 100%;
2120
@@ -31,10 +30,9 @@ const Root: React.FC = () => {
3130
<ThemeProvider theme={theme}>
3231
<LandingPageProvider>
3332
<GlobalStyle theme={theme} />
34-
<Header />
35-
<Layout>
36-
<LandingPage />
37-
</Layout>
33+
<BrowserRouter>
34+
<Routes />
35+
</BrowserRouter>
3836
</LandingPageProvider>
3937
</ThemeProvider>
4038
);

frontend/package-lock.json

+120
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
"dependencies": {
2222
"@testing-library/jest-dom": "^4.2.4",
2323
"@testing-library/react": "^9.4.0",
24+
"@types/react-router-dom": "^5.1.5",
2425
"jest": "^24.9.0",
2526
"react": "^16.12.0",
2627
"react-dom": "^16.12.0",
28+
"react-router-dom": "^5.2.0",
2729
"styled-components": "^4.4.1",
2830
"typescript": "^3.7.2"
2931
},

frontend/routes/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export enum ROUTES {
2+
LANDING_PAGE = "/",
3+
BIOGRAPHY_PAGE = "/biography",
4+
PUBLICATION_PAGE = "/blog/:publication",
5+
}

frontend/urls.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from django.urls import path
1+
from django.urls import path, re_path
22
from . import views
33

44

55
urlpatterns = [
66
path('', views.index ),
7+
re_path(r'^(?:.*)/?$', views.index)
78
]

0 commit comments

Comments
 (0)