Skip to content

Commit 02b02bf

Browse files
committed
React Router
1 parent c4d2607 commit 02b02bf

File tree

4 files changed

+143
-8
lines changed

4 files changed

+143
-8
lines changed

package-lock.json

Lines changed: 123 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"classnames": "2.2.6",
1616
"react": "17.0.1",
1717
"react-dom": "17.0.1",
18+
"react-router-dom": "5.2.0",
1819
"react-scripts": "4.0.1",
1920
"typescript": "4.1.3",
2021
"web-vitals": "1.1.0"
@@ -56,6 +57,7 @@
5657
"@fab/server": "1.0.0-rc.9",
5758
"@tailwindcss/postcss7-compat": "2.0.2",
5859
"@types/classnames": "2.2.11",
60+
"@types/react-router-dom": "5.1.7",
5961
"autoprefixer": "9.8.6",
6062
"postcss": "7.0.35",
6163
"tailwindcss": "npm:@tailwindcss/[email protected]"

src/App.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
import { Home } from "./components/Home";
1+
import { Home } from "./pages/Home";
2+
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
23

34
function App() {
4-
return <Home />;
5+
return (
6+
<Router>
7+
<Switch>
8+
<Route path="/">
9+
<Home />
10+
</Route>
11+
</Switch>
12+
</Router>
13+
);
514
}
615

716
export default App;

src/components/Home.tsx renamed to src/pages/Home.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FC, useState } from "react";
22
import { Menu, Transition } from "@headlessui/react";
33
import classNames from "classnames";
4+
import { Link } from "react-router-dom";
45

56
export const Home: FC = () => {
67
const [isOpen, setIsOpen] = useState(false);
@@ -207,13 +208,13 @@ export const Home: FC = () => {
207208
<div className="grid grid-cols-3 gap-8 items-center">
208209
<div className="col-span-2">
209210
<nav className="flex space-x-4">
210-
<a
211-
href="/"
211+
<Link
212+
to="/"
212213
className="text-white text-sm font-medium rounded-md bg-white bg-opacity-0 px-3 py-2 hover:bg-opacity-10"
213214
aria-current="page"
214215
>
215216
Home
216-
</a>
217+
</Link>
217218

218219
<a
219220
href="/"
@@ -341,12 +342,12 @@ export const Home: FC = () => {
341342
</div>
342343
</div>
343344
<div className="mt-3 px-2 space-y-1">
344-
<a
345-
href="/"
345+
<Link
346+
to="/"
346347
className="block rounded-md px-3 py-2 text-base text-gray-900 font-medium hover:bg-gray-100 hover:text-gray-800"
347348
>
348349
Home
349-
</a>
350+
</Link>
350351
<a
351352
href="/"
352353
className="block rounded-md px-3 py-2 text-base text-gray-900 font-medium hover:bg-gray-100 hover:text-gray-800"

0 commit comments

Comments
 (0)