├── public
├── robots.txt
├── favicon.ico
├── logo192.png
├── logo512.png
├── manifest.json
└── index.html
├── src
├── components
│ ├── Home.js
│ ├── Login.js
│ └── products
│ │ ├── AddProduct.js
│ │ ├── Products.js
│ │ ├── ProductDisplay.js
│ │ ├── Search.js
│ │ └── ListProducts.js
├── reportWebVitals.js
├── index.js
├── ProductsData.js
├── App.js
└── App.css
├── .gitignore
├── package.json
└── README.md
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/machadop1407/nested-routes-react-router-dom-v6/HEAD/public/favicon.ico
--------------------------------------------------------------------------------
/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/machadop1407/nested-routes-react-router-dom-v6/HEAD/public/logo192.png
--------------------------------------------------------------------------------
/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/machadop1407/nested-routes-react-router-dom-v6/HEAD/public/logo512.png
--------------------------------------------------------------------------------
/src/components/Home.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | function Home() {
4 | return (
5 |
6 |
Home Page
7 |
8 | );
9 | }
10 |
11 | export default Home;
12 |
--------------------------------------------------------------------------------
/src/components/Login.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | function Login() {
4 | return (
5 |
6 |
Login Page
7 |
8 | );
9 | }
10 |
11 | export default Login;
12 |
--------------------------------------------------------------------------------
/src/components/products/AddProduct.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | function AddProduct() {
4 | return (
5 |
6 |
Add Product
7 |
8 | );
9 | }
10 |
11 | export default AddProduct;
12 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/src/reportWebVitals.js:
--------------------------------------------------------------------------------
1 | const reportWebVitals = onPerfEntry => {
2 | if (onPerfEntry && onPerfEntry instanceof Function) {
3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
4 | getCLS(onPerfEntry);
5 | getFID(onPerfEntry);
6 | getFCP(onPerfEntry);
7 | getLCP(onPerfEntry);
8 | getTTFB(onPerfEntry);
9 | });
10 | }
11 | };
12 |
13 | export default reportWebVitals;
14 |
--------------------------------------------------------------------------------
/src/components/products/Products.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { Link, Outlet } from "react-router-dom";
3 |
4 | function Products() {
5 | return (
6 |
7 |
8 | Search
9 | List
10 | Add
11 |
12 |
13 |
14 |
15 | );
16 | }
17 |
18 | export default Products;
19 |
--------------------------------------------------------------------------------
/src/components/products/ProductDisplay.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { useParams } from "react-router-dom";
3 | import { ProductsData } from "../../ProductsData";
4 |
5 | function ProductDisplay() {
6 | const { id } = useParams();
7 | return (
8 |
9 |
10 |
{ProductsData[id - 1].name}
{" "}
11 |
{ProductsData[id - 1].description}
{" "}
12 |
13 |
14 | );
15 | }
16 |
17 | export default ProductDisplay;
18 |
--------------------------------------------------------------------------------
/src/components/products/Search.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | function Search() {
4 | return (
5 |
6 |
7 |
8 |
13 |
16 |
17 |
18 |
19 | );
20 | }
21 |
22 | export default Search;
23 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import ReactDOM from "react-dom";
3 | import App from "./App";
4 | import reportWebVitals from "./reportWebVitals";
5 |
6 | ReactDOM.render(
7 |
8 |
9 | ,
10 | document.getElementById("root")
11 | );
12 |
13 | // If you want to start measuring performance in your app, pass a function
14 | // to log results (for example: reportWebVitals(console.log))
15 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
16 | reportWebVitals();
17 |
--------------------------------------------------------------------------------
/src/ProductsData.js:
--------------------------------------------------------------------------------
1 | export const ProductsData = [
2 | {
3 | id: 1,
4 | name: "Product 1",
5 | description: "Description 1",
6 | price: 100,
7 | image: "https://via.placeholder.com/150",
8 | },
9 | {
10 | id: 2,
11 | name: "Product 2",
12 | description: "Description 2",
13 | price: 200,
14 | image: "https://via.placeholder.com/150",
15 | },
16 | {
17 | id: 3,
18 | name: "Product 3",
19 | description: "Description 3",
20 | price: 300,
21 | image: "https://via.placeholder.com/150",
22 | },
23 | ];
24 |
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/src/components/products/ListProducts.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { ProductsData } from "../../ProductsData";
3 | import { useNavigate } from "react-router-dom";
4 | function ListProducts() {
5 | const navigate = useNavigate();
6 | return (
7 |
8 |
9 | {ProductsData.map((product) => {
10 | return (
11 |
{
14 | navigate(`/products/${product.id}`);
15 | }}
16 | >
17 |
{product.name}
{product.description}
{" "}
18 |
19 | );
20 | })}
21 |
22 |
23 | );
24 | }
25 |
26 | export default ListProducts;
27 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nested-routes",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^5.14.1",
7 | "@testing-library/react": "^12.0.0",
8 | "@testing-library/user-event": "^13.2.1",
9 | "react": "^17.0.2",
10 | "react-dom": "^17.0.2",
11 | "react-router-dom": "^6.2.1",
12 | "react-scripts": "5.0.0",
13 | "web-vitals": "^2.1.0"
14 | },
15 | "scripts": {
16 | "start": "react-scripts start",
17 | "build": "react-scripts build",
18 | "test": "react-scripts test",
19 | "eject": "react-scripts eject"
20 | },
21 | "eslintConfig": {
22 | "extends": [
23 | "react-app",
24 | "react-app/jest"
25 | ]
26 | },
27 | "browserslist": {
28 | "production": [
29 | ">0.2%",
30 | "not dead",
31 | "not op_mini all"
32 | ],
33 | "development": [
34 | "last 1 chrome version",
35 | "last 1 firefox version",
36 | "last 1 safari version"
37 | ]
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import { BrowserRouter as Router, Link, Routes, Route } from "react-router-dom";
2 | import "./App.css";
3 | import Home from "./components/Home";
4 | import Products from "./components/products/Products";
5 | import Login from "./components/Login";
6 | import Search from "./components/products/Search";
7 | import AddProduct from "./components/products/AddProduct";
8 | import ProductDisplay from "./components/products/ProductDisplay";
9 | import ListProducts from "./components/products/ListProducts";
10 |
11 | function App() {
12 | return (
13 |
14 |
19 |
20 | } />
21 | } />
22 | }>
23 | } />
24 | } />
25 | } />
26 | } />
27 |
28 |
29 |
30 | );
31 | }
32 |
33 | export default App;
34 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | React App
28 |
29 |
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/src/App.css:
--------------------------------------------------------------------------------
1 | @import url(https://fonts.googleapis.com/css?family=Open+Sans);
2 |
3 | .App {
4 | text-align: center;
5 | }
6 |
7 | body {
8 | padding: 0%;
9 | margin: 0%;
10 | font-family: "Open Sans", sans-serif;
11 | }
12 |
13 | nav {
14 | margin: 0;
15 | width: 100%;
16 | height: 80px;
17 | background-color: rgb(69, 62, 249);
18 | display: flex;
19 | justify-content: center;
20 | align-items: center;
21 | color: white;
22 | text-decoration: none;
23 | }
24 |
25 | a {
26 | color: white;
27 | text-decoration: none;
28 | margin: 10px;
29 | font-size: 25px;
30 | }
31 |
32 | .search {
33 | width: 100%;
34 | position: relative;
35 | display: flex;
36 | }
37 |
38 | .searchTerm {
39 | width: 100%;
40 | border: 3px solid rgb(69, 62, 249);
41 | border-right: none;
42 | padding: 5px;
43 | height: 20px;
44 | border-radius: 5px 0 0 5px;
45 | outline: none;
46 | color: #9dbfaf;
47 | }
48 |
49 | .searchTerm:focus {
50 | color: rgb(69, 62, 249);
51 | }
52 |
53 | .searchButton {
54 | width: 40px;
55 | height: 36px;
56 | border: 1px solid rgb(69, 62, 249);
57 | background: rgb(69, 62, 249);
58 | text-align: center;
59 | color: #fff;
60 | border-radius: 0 5px 5px 0;
61 | cursor: pointer;
62 | font-size: 20px;
63 | }
64 |
65 | /*Resize the wrap to see the search bar change!*/
66 | .wrap {
67 | width: 30%;
68 | position: absolute;
69 | top: 50%;
70 | left: 50%;
71 | transform: translate(-50%, -50%);
72 | }
73 |
74 | .products {
75 | width: 100%;
76 | height: calc(100vh - 80px);
77 | display: flex;
78 | flex-direction: column;
79 | align-items: center;
80 | padding-top: 60px;
81 | }
82 | .productsNav {
83 | width: 70%;
84 | height: 80px;
85 | border-radius: 12px;
86 | display: flex;
87 | justify-content: center;
88 | }
89 |
90 | .productsNav a {
91 | width: 150px;
92 | height: 50px;
93 | background-color: rgb(69, 62, 249);
94 | border-radius: 5px;
95 | display: flex;
96 | align-items: center;
97 | justify-content: center;
98 | }
99 |
100 | .listOfProducts {
101 | width: 100%;
102 | height: calc(100vh - 80px);
103 | display: flex;
104 | justify-content: center;
105 | padding-top: 60px;
106 | }
107 |
108 | .productsList {
109 | columns: 3 auto;
110 | display: inline-block;
111 | }
112 |
113 | .productDisplay {
114 | width: 300px;
115 | height: 300px;
116 | background-color: rgb(233, 233, 233);
117 | cursor: pointer;
118 | }
119 | * {
120 | padding-top: 0;
121 | margin-top: 0;
122 | }
123 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Getting Started with Create React App
2 |
3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4 |
5 | ## Available Scripts
6 |
7 | In the project directory, you can run:
8 |
9 | ### `yarn start`
10 |
11 | Runs the app in the development mode.\
12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
13 |
14 | The page will reload when you make changes.\
15 | You may also see any lint errors in the console.
16 |
17 | ### `yarn test`
18 |
19 | Launches the test runner in the interactive watch mode.\
20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21 |
22 | ### `yarn build`
23 |
24 | Builds the app for production to the `build` folder.\
25 | It correctly bundles React in production mode and optimizes the build for the best performance.
26 |
27 | The build is minified and the filenames include the hashes.\
28 | Your app is ready to be deployed!
29 |
30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31 |
32 | ### `yarn eject`
33 |
34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!**
35 |
36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37 |
38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
39 |
40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
41 |
42 | ## Learn More
43 |
44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45 |
46 | To learn React, check out the [React documentation](https://reactjs.org/).
47 |
48 | ### Code Splitting
49 |
50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51 |
52 | ### Analyzing the Bundle Size
53 |
54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55 |
56 | ### Making a Progressive Web App
57 |
58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59 |
60 | ### Advanced Configuration
61 |
62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63 |
64 | ### Deployment
65 |
66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67 |
68 | ### `yarn build` fails to minify
69 |
70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
71 |
--------------------------------------------------------------------------------