feat(router): 添加首页路由并调整PC端路由结构
添加新的首页路由组件,实现设备检测自动跳转功能 重构PC端路由路径,移除冗余子路由配置
This commit is contained in:
34
Touchkebao/src/pages/index.tsx
Normal file
34
Touchkebao/src/pages/index.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import React, { useEffect } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import Layout from "@/components/Layout/Layout";
|
||||
|
||||
const IndexPage: React.FC = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
// 检测是否为移动端
|
||||
const isMobile = () => {
|
||||
const userAgent = navigator.userAgent;
|
||||
const mobileRegex =
|
||||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
|
||||
return mobileRegex.test(userAgent) || window.innerWidth <= 768;
|
||||
};
|
||||
|
||||
// 如果是移动端,跳转到/pc/dashboard
|
||||
if (isMobile()) {
|
||||
navigate("/mobile/dashboard");
|
||||
} else {
|
||||
navigate("/pc/dashboard");
|
||||
}
|
||||
}, [navigate]);
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<div>
|
||||
<h1>首页</h1>
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
|
||||
export default IndexPage;
|
||||
@@ -1,8 +1,13 @@
|
||||
import Login from "@/pages/login/Login";
|
||||
import Guide from "@/pages/guide";
|
||||
import Init from "@/pages/iframe/init";
|
||||
|
||||
import Index from "@/pages/index";
|
||||
const authRoutes = [
|
||||
{
|
||||
path: "/",
|
||||
element: <Index />,
|
||||
auth: false, // 需要登录
|
||||
},
|
||||
{
|
||||
path: "/init",
|
||||
element: <Init />,
|
||||
|
||||
@@ -4,14 +4,10 @@ import Dashboard from "@/pages/pc/ckbox/dashboard";
|
||||
|
||||
const ckboxRoutes = [
|
||||
{
|
||||
path: "/ckbox",
|
||||
path: "/pc",
|
||||
element: <CkboxPage />,
|
||||
auth: true,
|
||||
children: [
|
||||
{
|
||||
path: "",
|
||||
element: <Dashboard />,
|
||||
},
|
||||
{
|
||||
path: "dashboard",
|
||||
element: <Dashboard />,
|
||||
|
||||
Reference in New Issue
Block a user