From 83c59aebab4c36207e0c66afad4a33aab6022c20 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Mon, 28 Oct 2024 12:24:59 +0800 Subject: [PATCH] 12. react-router --- package-lock.json | 39 +++++++++++++++++++++++++++++++++++++++ package.json | 1 + src/App.css | 4 ++++ src/App.js | 28 +++++++++++++++++++++++++++- src/index.js | 5 ++++- 5 files changed, 75 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8be3f0c..cab29ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "proptypes": "^1.1.0", "react": "^18.3.1", "react-dom": "^18.3.1", + "react-router-dom": "^6.27.0", "react-scripts": "5.0.1", "web-vitals": "^2.1.4" } @@ -3247,6 +3248,14 @@ } } }, + "node_modules/@remix-run/router": { + "version": "1.20.0", + "resolved": "https://registry.npmmirror.com/@remix-run/router/-/router-1.20.0.tgz", + "integrity": "sha512-mUnk8rPJBI9loFDZ+YzPGdeniYK+FTmRD1TMCz7ev2SNIozyKKpnGgsxO34u6Z4z/t0ITuu7voi/AshfsGsgFg==", + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/@rollup/plugin-babel": { "version": "5.3.1", "resolved": "https://registry.npmmirror.com/@rollup/plugin-babel/-/plugin-babel-5.3.1.tgz", @@ -14901,6 +14910,36 @@ "node": ">=0.10.0" } }, + "node_modules/react-router": { + "version": "6.27.0", + "resolved": "https://registry.npmmirror.com/react-router/-/react-router-6.27.0.tgz", + "integrity": "sha512-YA+HGZXz4jaAkVoYBE98VQl+nVzI+cVI2Oj/06F5ZM+0u3TgedN9Y9kmMRo2mnkSK2nCpNQn0DVob4HCsY/WLw==", + "dependencies": { + "@remix-run/router": "1.20.0" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "react": ">=16.8" + } + }, + "node_modules/react-router-dom": { + "version": "6.27.0", + "resolved": "https://registry.npmmirror.com/react-router-dom/-/react-router-dom-6.27.0.tgz", + "integrity": "sha512-+bvtFWMC0DgAFrfKXKG9Fc+BcXWRUO1aJIihbB79xaeq0v5UzfvnM5houGUm1Y461WVRcgAQ+Clh5rdb1eCx4g==", + "dependencies": { + "@remix-run/router": "1.20.0", + "react-router": "6.27.0" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "react": ">=16.8", + "react-dom": ">=16.8" + } + }, "node_modules/react-scripts": { "version": "5.0.1", "resolved": "https://registry.npmmirror.com/react-scripts/-/react-scripts-5.0.1.tgz", diff --git a/package.json b/package.json index 813845f..192b155 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "proptypes": "^1.1.0", "react": "^18.3.1", "react-dom": "^18.3.1", + "react-router-dom": "^6.27.0", "react-scripts": "5.0.1", "web-vitals": "^2.1.4" }, diff --git a/src/App.css b/src/App.css index ed2c176..3b52910 100644 --- a/src/App.css +++ b/src/App.css @@ -37,3 +37,7 @@ transform: rotate(360deg); } } + +.active { + color: orange; +} diff --git a/src/App.js b/src/App.js index 8eba94a..001cc13 100644 --- a/src/App.js +++ b/src/App.js @@ -5,6 +5,7 @@ import './App.css'; import InputComponent from "./components/InputComponent"; import SonComponent from "./components/SonComponent"; import SonComponent2 from "./components/SonComponent2"; +import {Link, NavLink, Route, Routes} from "react-router-dom"; function App() { // vue3 组合式 API @@ -170,6 +171,29 @@ function App() { return (