Skip to content

Commit 7bc7ef7

Browse files
committed
chore: add routes
1 parent 39709e0 commit 7bc7ef7

File tree

7 files changed

+115
-67
lines changed

7 files changed

+115
-67
lines changed

web/pnpm-lock.yaml

Lines changed: 47 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/src/App.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import React from 'react';
2-
import { ConfigProvider } from 'antd';
32
import AppLayout from './components/Layout';
43
import './styles/global.scss';
54

65
const App: React.FC = () => {
76
return (
8-
<ConfigProvider theme={{ token: { colorPrimary: '#00b96b' } }}>
9-
<div className="app-container">
10-
<AppLayout/>
11-
</div>
12-
</ConfigProvider>
7+
<div className="app-container">
8+
<AppLayout/>
9+
</div>
1310
)
1411
};
1512

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react';
2+
import { Route, Redirect } from 'react-router-dom';
3+
4+
const PrivateRoute = ({ component: Component, ...rest }) => {
5+
const isAuthenticated = !!localStorage.getItem('token'); // 检查用户是否登录
6+
7+
return (
8+
<Route
9+
{...rest}
10+
render={(props: React.JSX.IntrinsicAttributes) =>
11+
isAuthenticated ? (
12+
<Component {...props} />
13+
) : (
14+
<Redirect to="/login"/>
15+
)
16+
}
17+
/>
18+
);
19+
};
20+
21+
export default PrivateRoute;

web/src/config/routes.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react';
2+
import { BrowserRouter, Routes, Route } from 'react-router-dom';
3+
4+
import Home from '../pages/Home';
5+
import Login from '../pages/Login';
6+
import NotFound from '../pages/NotFound';
7+
8+
const Routers = () => {
9+
return (
10+
<BrowserRouter>
11+
<Routes>
12+
<Route path="/home" element={<Home/>}/>
13+
<Route exact path="/" component={Home}/>
14+
15+
{/* 登录页 */}
16+
<Route path="/login" component={Login}/>
17+
18+
{/* 404 页面 */}
19+
<Route component={NotFound}/>
20+
</Routes>
21+
</BrowserRouter>
22+
);
23+
};
24+
25+
export default Routers;

web/src/index.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { createRoot } from 'react-dom/client';
33
import App from './App';
4+
import { ConfigProvider } from 'antd';
45
import { LanguageProvider } from './utils/LanguageContext';
56

67

@@ -9,12 +10,8 @@ const container = document.getElementById('root');
910
const root = createRoot(container!); // 创建根
1011
root.render(
1112
<LanguageProvider>
12-
<App/>
13+
<ConfigProvider theme={{ token: { colorPrimary: '#00b96b' } }}>
14+
<App/>
15+
</ConfigProvider>
1316
</LanguageProvider>,
14-
); // 使用新 API 渲染组件
15-
// const root = ReactDOM.createRoot(document.getElementById('root'));
16-
// root.render(
17-
// <React.StrictMode>
18-
// <App />
19-
// </React.StrictMode>
20-
// );
17+
);

web/src/pages/Home/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react';
2+
3+
const Home: React.FC = () => {
4+
return <div>Welcome to the Home Page!</div>;
5+
};
6+
7+
export default Home;

web/src/pages/NotFound/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react';
2+
3+
const NotFound: React.FC = () => {
4+
return <div>404 - Page Not Found</div>;
5+
};
6+
7+
export default NotFound;

0 commit comments

Comments
 (0)