From 7050f15f0a61451ab5c0e981b5881864cb471e46 Mon Sep 17 00:00:00 2001 From: mashen Date: Thu, 9 Apr 2026 13:46:50 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=85=8D=E7=BD=AE=20React=20Router=20?= =?UTF-8?q?=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 配置首页路由 - 配置城市列表页路由 - 配置城市详情页路由 - 配置个人中心页路由 - 配置 404 页面 - 集成 MobX stores --- frontend/src/App.js | 102 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 96 insertions(+), 6 deletions(-) diff --git a/frontend/src/App.js b/frontend/src/App.js index cacbc41..41be71a 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -1,6 +1,12 @@ import React from 'react'; import { Routes, Route } from 'react-router-dom'; +import { observer } from 'mobx-react-lite'; import styled from 'styled-components'; +import { useAuthStore } from './stores/AuthStore'; +import Layout from './components/common/Layout'; +import Loading from './components/common/Loading'; +import CitiesPage from './components/region/CitiesPage'; +import CityDetailPage from './components/region/CityDetailPage'; const Container = styled.div` max-width: 1200px; @@ -20,16 +26,100 @@ const Title = styled.h1` `; function App() { + const authStore = useAuthStore(); + + // Fetch current user on app load + React.useEffect(() => { + if (authStore.isAuthenticated) { + authStore.fetchCurrentUser(); + } + }, [authStore]); + return ( - -
- React + Django App -
+ - Welcome to the app!} /> + } /> + } /> + } /> + } /> + } /> -
+ ); } +const HomePage = observer(() => { + return ( + +
+ 欢迎来到城市手册 +

探索每个城市的故事与特色

+
+
+

热门城市

+

即将推出...

+
+
+

最新文章

+

即将推出...

+
+
+ ); +}); + +const UserProfilePage = observer(() => { + const authStore = useAuthStore(); + const userStore = useUserStore(); + + React.useEffect(() => { + if (authStore.isAuthenticated) { + userStore.fetchCurrentUser(); + } + }, [authStore, userStore]); + + if (!authStore.isAuthenticated) { + return ( + +

请先登录

+
+ ); + } + + if (userStore.loading) { + return ; + } + + return ( + +
+ 个人中心 +
+ {userStore.user && ( +
+

用户信息

+

用户名: {userStore.user.username}

+

邮箱: {userStore.user.email}

+

角色: {userStore.user.role_display}

+ +

统计

+

文章数: {userStore.user.articles_count}

+

服务数: {userStore.user.services_count}

+

评论数: {userStore.user.comments_count}

+

点赞数: {userStore.user.likes_count}

+

收藏数: {userStore.user.favorites_count}

+
+ )} +
+ ); +}); + +const NotFoundPage = () => ( + +
+ 404 +
+

页面未找到

+
+); + export default App; \ No newline at end of file