From 9c0dfd68fb3120f3ee911457903729bf1c05aed8 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Wed, 16 Dec 2020 02:34:07 +0200 Subject: [PATCH] Added router --- package-lock.json | 83 +++++++++++++++++++ package.json | 1 + src/App.js | 15 ++-- src/components/layout/PageNotFound.js | 5 ++ src/components/layout/Switcher.js | 18 ++++ .../about/components/AboutContainer.js | 7 ++ .../login/components/LoginContainer.js | 17 +++- src/index.js | 5 +- 8 files changed, 143 insertions(+), 8 deletions(-) create mode 100644 src/components/layout/PageNotFound.js create mode 100644 src/components/layout/Switcher.js create mode 100644 src/features/about/components/AboutContainer.js diff --git a/package-lock.json b/package-lock.json index 1a55fc9..81aa6d4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7177,6 +7177,19 @@ "resolved": "https://registry.npmjs.org/hex-color-regex/-/hex-color-regex-1.1.0.tgz", "integrity": "sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ==" }, + "history": { + "version": "4.10.1", + "resolved": "https://registry.npmjs.org/history/-/history-4.10.1.tgz", + "integrity": "sha512-36nwAD620w12kuzPAsyINPWJqlNbij+hpK1k9XRloDtym8mxzGYl2c17LnV6IAGB2Dmg4tEa7G7DlawS0+qjew==", + "requires": { + "@babel/runtime": "^7.1.2", + "loose-envify": "^1.2.0", + "resolve-pathname": "^3.0.0", + "tiny-invariant": "^1.0.2", + "tiny-warning": "^1.0.0", + "value-equal": "^1.0.1" + } + }, "hmac-drbg": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", @@ -10155,6 +10168,15 @@ "resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz", "integrity": "sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==" }, + "mini-create-react-context": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/mini-create-react-context/-/mini-create-react-context-0.4.1.tgz", + "integrity": "sha512-YWCYEmd5CQeHGSAKrYvXgmzzkrvssZcuuQDDeqkT+PziKGMgE+0MCCtcKbROzocGBG1meBLl2FotlRwf4gAzbQ==", + "requires": { + "@babel/runtime": "^7.12.1", + "tiny-warning": "^1.0.3" + } + }, "mini-css-extract-plugin": { "version": "0.11.3", "resolved": "https://registry.npmjs.org/mini-css-extract-plugin/-/mini-css-extract-plugin-0.11.3.tgz", @@ -12579,6 +12601,52 @@ "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.8.3.tgz", "integrity": "sha512-X8jZHc7nCMjaCqoU+V2I0cOhNW+QMBwSUkeXnTi8IPe6zaRWfn60ZzvFDZqWPfmSJfjub7dDW1SP0jaHWLu/hg==" }, + "react-router": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-5.2.0.tgz", + "integrity": "sha512-smz1DUuFHRKdcJC0jobGo8cVbhO3x50tCL4icacOlcwDOEQPq4TMqwx3sY1TP+DvtTgz4nm3thuo7A+BK2U0Dw==", + "requires": { + "@babel/runtime": "^7.1.2", + "history": "^4.9.0", + "hoist-non-react-statics": "^3.1.0", + "loose-envify": "^1.3.1", + "mini-create-react-context": "^0.4.0", + "path-to-regexp": "^1.7.0", + "prop-types": "^15.6.2", + "react-is": "^16.6.0", + "tiny-invariant": "^1.0.2", + "tiny-warning": "^1.0.0" + }, + "dependencies": { + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" + }, + "path-to-regexp": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", + "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", + "requires": { + "isarray": "0.0.1" + } + } + } + }, + "react-router-dom": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-5.2.0.tgz", + "integrity": "sha512-gxAmfylo2QUjcwxI63RhQ5G85Qqt4voZpUXSEqCwykV0baaOTQDR1f0PmY8AELqIyVc0NEZUj0Gov5lNGcXgsA==", + "requires": { + "@babel/runtime": "^7.1.2", + "history": "^4.9.0", + "loose-envify": "^1.3.1", + "prop-types": "^15.6.2", + "react-router": "5.2.0", + "tiny-invariant": "^1.0.2", + "tiny-warning": "^1.0.0" + } + }, "react-scripts": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/react-scripts/-/react-scripts-4.0.1.tgz", @@ -13066,6 +13134,11 @@ "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==" }, + "resolve-pathname": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/resolve-pathname/-/resolve-pathname-3.0.0.tgz", + "integrity": "sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng==" + }, "resolve-url": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz", @@ -14718,6 +14791,11 @@ "resolved": "https://registry.npmjs.org/timsort/-/timsort-0.3.0.tgz", "integrity": "sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=" }, + "tiny-invariant": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.1.0.tgz", + "integrity": "sha512-ytxQvrb1cPc9WBEI/HSeYYoGD0kWnGEOR8RY6KomWLBVhqz0RgTwVO9dLrGz7dC+nN9llyI7OKAgRq8Vq4ZBSw==" + }, "tiny-warning": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/tiny-warning/-/tiny-warning-1.0.3.tgz", @@ -15193,6 +15271,11 @@ "spdx-expression-parse": "^3.0.0" } }, + "value-equal": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/value-equal/-/value-equal-1.0.1.tgz", + "integrity": "sha512-NOJ6JZCAWr0zlxZt+xqCHNTEKOsrks2HQd4MqhP1qy4z1SkbEP467eNx6TgDKXMvUOb+OENfJCZwM+16n7fRfw==" + }, "vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", diff --git a/package.json b/package.json index 953fab6..6cefca5 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "@testing-library/user-event": "^12.5.0", "react": "^17.0.1", "react-dom": "^17.0.1", + "react-router-dom": "^5.2.0", "react-scripts": "4.0.1", "web-vitals": "^0.2.4" }, diff --git a/src/App.js b/src/App.js index 01906e4..e0dca46 100644 --- a/src/App.js +++ b/src/App.js @@ -1,13 +1,16 @@ +import React, { Suspense } from "react"; import "./App.css"; -import LoginContainer from "./features/login/components/LoginContainer"; +import Switcher from "./components/layout/Switcher"; function App() { return ( -
-
- -
-
+ Loading...}> +
+
+ +
+
+
); } diff --git a/src/components/layout/PageNotFound.js b/src/components/layout/PageNotFound.js new file mode 100644 index 0000000..70a8d0f --- /dev/null +++ b/src/components/layout/PageNotFound.js @@ -0,0 +1,5 @@ +import React from "react"; + +const PageNotFound = () =>

Oops! Page not found

; + +export default PageNotFound; diff --git a/src/components/layout/Switcher.js b/src/components/layout/Switcher.js new file mode 100644 index 0000000..f53c63e --- /dev/null +++ b/src/components/layout/Switcher.js @@ -0,0 +1,18 @@ +import React from "react"; +import { Route, Switch } from "react-router-dom"; +import PageNotFound from "./PageNotFound"; +import LoginContainer from "../../features/login/components/LoginContainer"; +import AboutContainer from "../../features/about/components/AboutContainer"; + +const Switcher = () => { + return ( + + + + + + + ); +}; + +export default Switcher; diff --git a/src/features/about/components/AboutContainer.js b/src/features/about/components/AboutContainer.js new file mode 100644 index 0000000..9e791ef --- /dev/null +++ b/src/features/about/components/AboutContainer.js @@ -0,0 +1,7 @@ +import React from "react"; + +const AboutContainer = () => { + return
TEST
; +}; + +export default AboutContainer; diff --git a/src/features/login/components/LoginContainer.js b/src/features/login/components/LoginContainer.js index c4aeb05..8c704f8 100644 --- a/src/features/login/components/LoginContainer.js +++ b/src/features/login/components/LoginContainer.js @@ -1,8 +1,23 @@ import React from "react"; import LoginComponent from "./LoginComponent"; +import Button from "@material-ui/core/Button"; +import { useHistory } from "react-router-dom"; const LoginContainer = () => { - return ; + const history = useHistory(); + + const handleMove = () => { + history.push("about"); + }; + + return ( + <> + + + + ); }; export default LoginContainer; diff --git a/src/index.js b/src/index.js index ad9cbbb..8054340 100644 --- a/src/index.js +++ b/src/index.js @@ -3,10 +3,13 @@ import ReactDOM from "react-dom"; import "./index.css"; import App from "./App"; import reportWebVitals from "./reportWebVitals"; +import { BrowserRouter as Router } from "react-router-dom"; ReactDOM.render( - + + + , document.getElementById("root") );