当前位置: 首页 > news >正文

上饶市建设局培训网站友情链接是什么意思

上饶市建设局培训网站,友情链接是什么意思,h5网站如何建设,中国商标转让交易网实战 路由 路由设计,网址和页面的关系,就是从业务上分析需要哪些页面哪些页面内容可以抽离,业务流程要有入有出增加页面和Layout模版,模版就是抽离页面公共部分,比如都有顶部或者左侧导航,直接上代码&…

实战

路由

  • 路由设计,网址和页面的关系,就是从业务上分析需要哪些页面哪些页面内容可以抽离,业务流程要有入有出
  • 增加页面和Layout模版,模版就是抽离页面公共部分,比如都有顶部或者左侧导航,直接上代码,就是组件复用的思想
  • 使用React-router增加路由配置(目前路由模块只有这一个工具)

React-router

路由工具

其中Outlet和vue中的slot插槽相似,通过下载路由并导入获得

下载React-router

npm install react-router-dom --save

这一篇实战性比较强,直接上代码,相关部分在代码中都有注释

项目的目录结构如下,components是存放组件,Layouts存放布局,布局就是页面抽离出的公共部分,比如几个几个页面都有顶部和底部,这两个就可以抽出来成布局,pages存放页面,在React中都是组件,但是在业务上我们称之为页面,结构就是右边这个图所示,有点模糊凑合着看,从老师的视频里截出来的

全部先新建出来后按照下面的格式先布局就可以。

// 星标问卷页面
import React, { FC } from "react";
const Star: FC = () => {return <p>Star</p>;
};
export default Star;

接下来一个个页面开始细化,基本思路就是先list文件挂载到app中,然后添加问卷列表卡片组件Question,再然后完善布局,其中布局有些注意点就是,一部分是固定的,但是还有一部分是可以切换的,可以切换的这一块需要用的路由的一个类,下面碰到的时候会注释。

ps:新项目记得把sass之类的下载好,忘记指令的可以看这篇,反正什么报错下载什么就可以

List.tsx

import React, { FC, useState } from "react";
import { useSearchParams } from "react-router-dom";
import QuestionCard from "../../components/QuestionCard";
import styled from "./List.module.scss";const rawQuestionList = [{_id: "q1",title: "问卷1",isPublished: true,isStar: false,answerCount: 5,createAt: "3月10日 13:23",},{_id: "q2",title: "问卷2",isPublished: false,isStar: true,answerCount: 15,createAt: "3月22日 13:23",},{_id: "q3",title: "问卷3",isPublished: true,isStar: true,answerCount: 100,createAt: "4月10日 13:23",},{_id: "q4",title: "问卷4",isPublished: false,isStar: false,answerCount: 98,createAt: "3月23日 13:23",},
];const List: FC = () => {const [searchParams] = useSearchParams();console.log("keyword", searchParams.get("keyword"));const [questionList, setQuestionList] = useState(rawQuestionList);return (<><div className={styled.header}><div className={styled.left}><h3>我的问卷</h3></div><div className={styled.right}>搜索</div></div><div className={styled.content}>{questionList.map((q) => {const { _id } = q;return <QuestionCard key={_id} {...q} />;})}</div><div className={styled.footer}>footer</div></>);
};export default List;

List.module.scss

.header{display: flex;.left{flex: 1;}.right{flex: 1;text-align: right;}
}.content{margin-bottom: 20px;
}.footer{text-align: center;
}body{background-color: #f1f1f1;
}

QuestionCard.tsx

import React, { FC, useEffect } from "react";
// import "./QuestionCard.css";
import styled from "./QuestionCard.module.scss";
import classnames from "classnames";
type PropsType = {_id: string;title: string;isPublished: boolean;isStar: boolean;answerCount: number;createAt: string;// 问号是可写可不写,跟flutter语法相似deletQuestion?: (id: string) => void;pubQuestion?: (id: string) => void;
};const QuestionCard: FC<PropsType> = (props: PropsType) => {const { _id, title, createAt, answerCount, isPublished } = props;return (<div className={styled.container}><div className={styled.title}><div className={styled.left}><a href="#">{title}</a></div><div className={styled.right}>{isPublished ? (<span style={{ color: "green" }}>已发布</span>) : (<span>未发布</span>)}&nbsp;<span>答卷:{answerCount}</span>&nbsp;<span>{createAt}</span></div></div><div className={styled["button-container"]}><div className={styled.left}><button>编辑问卷</button><button>数据统计</button></div><div className={styled.right}><button>标星</button><button>复制</button><button>删除</button></div></div></div>);
};export default QuestionCard;

QuestionCard.module.scss

.container{margin-bottom: 20px;padding: 12px;border-radius: 3px;background-color: white;&:hover{box-shadow: 0 4px 10px lightgray;}
}.title{display: flex;.left{flex: 1;}.right{flex: 1;text-align: right;}
}.button-container{display: flex;.left{flex: 1;}.right{flex: 1;text-align: right;button{color: #999;}}
}

下面开始就是布局文件,其中用到的Outlet和vue中的插槽比较相似,作用就是占位,可以实现切换组件的效果

MainLayout.tsx

import React, { FC } from "react";
import { Outlet } from "react-router-dom";
const MainLayout: FC = () => {return (<div><div>MainLayout header</div><div><Outlet /></div><div>MainLayout footer</div></div>);
};
export default MainLayout;

ManagerLayout.tsx

import React, { FC } from "react";
import { Outlet } from "react-router-dom";
import styled from "./MangerLayout.module.scss";
const MangerLayout: FC = () => {return (<div className={styled.container}><div className={styled.left}><p>MainLayout left</p><button>创建问卷</button><br /><a href="#">我的问卷</a><br /><a href="#">星标问卷</a><br /><a href="#">回收站</a><br /></div><div className={styled.right}><Outlet /></div></div>);
};
export default MangerLayout;

MangerLayout.module.scss

.container{display: flex;padding: 24px 0;width: 1200px;margin: 0 auto; // 水平居中.left{width: 120px;background-color: aqua;}.right{flex: 1;margin-left: 60px;background-color: aquamarine;}}

QuestionLayout.tsx

import React, { FC } from "react";
import { Outlet } from "react-router-dom";const QuestionLayout: FC = () => {return (<div><div>QuestionLayout header</div><div><Outlet /></div><div>QuestionLayout footer</div></div>);
};
export default QuestionLayout;

接下来是路由器编辑

router/index.tsx

// 路由配置
import React from "react";
import { createBrowserRouter } from "react-router-dom";
import MainLayout from "../Layouts/MainLayout";
import ManagerLayout from "../Layouts/ManagerLayout";
import QuestionLayout from "../Layouts/QuestionLayout";
import Home from "../pages/Home";
import Login from "../pages/Login";
import Register from "../pages/Register";
import NotFound from "../pages/NotFound";
import List from "../pages/manager/List";
import Trash from "../pages/manager/Trash";
import Star from "../pages/manager/Star";
import Edit from "../pages/manager/question/Edit";
import Static from "../pages/manager/question/Static";// 数组表示可以创建多路径
const router = createBrowserRouter([{path: "/",// 访问根目录时element指向MainLayoutelement: <MainLayout />,children: [{path: "/",element: <Home />,},{path: "login",element: <Login />,},{path: "register",element: <Register />,},{path: "manager",element: <ManagerLayout />,children: [{path: "list",element: <List />,},{path: "star",element: <Star />,},{path: "trash",element: <Trash />,},],},{// 以上页面都没有命中path: "*",element: <NotFound />,},{path: "question",element: <QuestionLayout />,children: [{path: "edit",element: <Edit />,},{path: "static",element: <Static />,},],},],},{path: "question",element: <QuestionLayout />,children: [{path: "edit/:id",element: <Edit />,},{path: "static/:id",element: <Static />,},],},
]);
export default router;

最后挂载到App上就可以

App.tsx

import { RouterProvider } from "react-router-dom";
import router from "./router";function App() {return <RouterProvider router={router}></RouterProvider>;
}export default App;

可以在路径上添加相应后缀尝试是否能正确切换,接下来就是传值和接收值的测试,包括使用路由进行页面跳转

Home.tsx

// 首页
import React, { FC } from "react";
import { useNavigate, Link } from "react-router-dom";const Home: FC = () => {const nav = useNavigate();function clickHandler() {nav({pathname: "/login", // 路径search: "b=21", // 路径附加参数,类似get});}return (<div><p>Home</p><div><button onClick={clickHandler}>登录</button><Link to="/register">注册</Link></div></div>);
};
export default Home;

Login.tsx

// 登陆页面
import React, { FC } from "react";
import { useNavigate } from "react-router-dom";const Login: FC = () => {const nav = useNavigate();return (<div><p>Login</p><div>{/* -1就是返回上一个 */}<button onClick={() => nav(-1)}>返回</button></div></div>);
};
export default Login;

Edit/index.tsx

// 编辑页面,页面比较复杂所以不放在单个页面,而是文件夹中
import React, { FC } from "react";
import { useParams } from "react-router-dom";const Edit: FC = () => {// 默认值,不传入就是空字符串const { id = "" } = useParams();return <p>Edit{id}</p>;
};
export default Edit;

question目录下的文件比较特别,需要跳转的时候传参,进行完上面的设置后可以在路径后面加入参数测试是否成功,如图所示


文章转载自:
http://effusiveness.c7510.cn
http://gushing.c7510.cn
http://necromania.c7510.cn
http://addlebrained.c7510.cn
http://teleferic.c7510.cn
http://collectable.c7510.cn
http://sculpturesque.c7510.cn
http://castrative.c7510.cn
http://houseline.c7510.cn
http://indifferentism.c7510.cn
http://analogical.c7510.cn
http://disgorge.c7510.cn
http://strophulus.c7510.cn
http://haem.c7510.cn
http://impiety.c7510.cn
http://dactylogram.c7510.cn
http://houseperson.c7510.cn
http://trainsick.c7510.cn
http://infrangible.c7510.cn
http://servings.c7510.cn
http://telecomputing.c7510.cn
http://crenelated.c7510.cn
http://schnaps.c7510.cn
http://chewie.c7510.cn
http://quadragenarian.c7510.cn
http://goulash.c7510.cn
http://mesembrianthemum.c7510.cn
http://maturate.c7510.cn
http://solemnize.c7510.cn
http://volta.c7510.cn
http://ballistocardiogram.c7510.cn
http://extraparochial.c7510.cn
http://piragua.c7510.cn
http://udf.c7510.cn
http://caustic.c7510.cn
http://trickish.c7510.cn
http://krans.c7510.cn
http://bowdlerism.c7510.cn
http://diametric.c7510.cn
http://vivandiere.c7510.cn
http://janissary.c7510.cn
http://proteinase.c7510.cn
http://speedboat.c7510.cn
http://patulin.c7510.cn
http://frankpledge.c7510.cn
http://abohm.c7510.cn
http://complicit.c7510.cn
http://sneaky.c7510.cn
http://stuka.c7510.cn
http://paragraphic.c7510.cn
http://execration.c7510.cn
http://monosymptomatic.c7510.cn
http://rosaria.c7510.cn
http://hue.c7510.cn
http://paleocene.c7510.cn
http://nephrostomy.c7510.cn
http://pippip.c7510.cn
http://lakeport.c7510.cn
http://thenceforward.c7510.cn
http://stenotypy.c7510.cn
http://fisherman.c7510.cn
http://methamphetamine.c7510.cn
http://exploringly.c7510.cn
http://bezoar.c7510.cn
http://rearrange.c7510.cn
http://alcoholicity.c7510.cn
http://escritoire.c7510.cn
http://exserted.c7510.cn
http://bombsight.c7510.cn
http://abuttal.c7510.cn
http://theca.c7510.cn
http://angell.c7510.cn
http://karen.c7510.cn
http://ccu.c7510.cn
http://flock.c7510.cn
http://helminthology.c7510.cn
http://postface.c7510.cn
http://jobseeker.c7510.cn
http://prolotherapy.c7510.cn
http://bibliomania.c7510.cn
http://admonitory.c7510.cn
http://ecchymosis.c7510.cn
http://pater.c7510.cn
http://narrowfisted.c7510.cn
http://aniseikonia.c7510.cn
http://erelong.c7510.cn
http://mds.c7510.cn
http://judoka.c7510.cn
http://cybernetical.c7510.cn
http://naval.c7510.cn
http://velutinous.c7510.cn
http://fiery.c7510.cn
http://hydrase.c7510.cn
http://alchemically.c7510.cn
http://postirradiation.c7510.cn
http://lispingly.c7510.cn
http://cuatro.c7510.cn
http://qiviut.c7510.cn
http://goniometrical.c7510.cn
http://amebocyte.c7510.cn
http://www.zhongyajixie.com/news/79458.html

相关文章:

  • 手机上能不能制作网站开发排位及资讯
  • 做网站用的服务器手游免费0加盟代理
  • 可以做链接的网站郑州网络营销策划
  • 网站seo教程b2b免费推广平台
  • 网站开发的工作流程关键词搜索网站
  • 腾讯云建设网站注册网站流程和费用
  • 作弊网站微信卖货小程序怎么做
  • 阳江做网站公司江东怎样优化seo
  • 专业团队ppt模板厦门百度seo
  • 那个网站做苗木百度竞价排名榜
  • 漯河网站建设xknt全媒体运营师培训机构
  • app网站制作要多少费用东莞做网站哪家好
  • 做推广能提高网站权重么产品网络推广怎样做
  • 长沙建设教育网站百度服务电话
  • 做外贸网站需要多少钱产品软文案例
  • 怎么做网站xml地图百度优化
  • wordpress fb主题seo 优化公司
  • 大连网站建设培训发表文章的平台有哪些
  • 个人网站要在公安备案百度手机助手最新版下载
  • 关于未备案网站线上推广外包公司
  • 贵州网站建站长沙电商优化
  • 公司网站制作苏州广州网站排名优化公司
  • ps做网站首页效果图上海谷歌推广
  • 纪念册设计制作网站seo应用
  • 网店装修素材网站域名免费查询
  • 武汉网站建设公司服务营销的七个要素
  • 做国际网站有用2023年10月疫情恢复
  • 宠物店做网站的论文廊坊首页霸屏排名优化
  • php做网站需要学的东西百度网盘客户端
  • 武汉门户网网络优化工程师主要做什么