今天用react写了一个小小的DEMO:

回答|共 21 个

legs+ 发表于 前天 17:08| 字数 5 | 显示全部楼层

精华来了:


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

legs+ 发表于 昨天 22:08| 字数 1,512 | 显示全部楼层




闲来无事,用React的Router写了一个Demo


  1. import React from "react";
  2. import { BrowserRouter as Router, Routes, Route, Link } from "react-router-dom";

  3. // 首页组件
  4. function Home() {
  5.   return <h2 style={{ margin: 0 }}>首页</h2>;
  6. }

  7. // 关于我们组件
  8. function About() {
  9.   return <h2 style={{ margin: 0 }}>关于我们</h2>;
  10. }

  11. // 主应用组件
  12. function App() {
  13.   return (
  14.     <div
  15.       style={{
  16.         minHeight: "100vh",
  17.         display: "flex",
  18.         flexDirection: "column",
  19.         alignItems: "center",
  20.         justifyContent: "center",
  21.         background: "#f5f7fa",
  22.       }}
  23.     >
  24.       <Router>
  25.         <nav
  26.           style={{
  27.             marginBottom: "2rem",
  28.             background: "#fff",
  29.             padding: "12px 32px",
  30.             borderRadius: "12px",
  31.             boxShadow: "0 2px 12px rgba(0,0,0,0.08)",
  32.             display: "flex",
  33.             gap: "1.5rem",
  34.             fontSize: "1.1rem",
  35.             fontWeight: 500,
  36.           }}
  37.         >
  38.           <Link to="/" style={{ textDecoration: "none", color: "#222" }}>
  39.             首页
  40.           </Link>
  41.           <span style={{ color: "#ccc" }}>|</span>
  42.           <Link to="/about" style={{ textDecoration: "none", color: "#222" }}>
  43.             关于
  44.           </Link>
  45.         </nav>

  46.         <div
  47.           style={{
  48.             background: "#fff",
  49.             padding: "32px 48px",
  50.             borderRadius: "16px",
  51.             boxShadow: "0 4px 24px rgba(0,0,0,0.10)",
  52.             minWidth: "260px",
  53.             textAlign: "center",
  54.           }}
  55.         >
  56.           <Routes>
  57.             <Route path="/" element={<Home />} />
  58.             <Route path="/about" element={<About />} />
  59.           </Routes>
  60.         </div>
  61.       </Router>
  62.     </div>
  63.   );
  64. }

  65. export default App;
复制代码


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

热门推荐