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

策划公司网站今日头条收录入口

策划公司网站,今日头条收录入口,微信公众号制作图文,北京建设工程招标信息网相信很多React初学者第一次搭建自己的项目,搭建时会无从下手,本篇适合快速实现功能,熟悉React项目搭建流程。 目录 一、创建项目react-item 二、调整项目目录结构 三、使用scss预处理器 四、组件库Ant Design 五、配置基础路由 六、配置…

相信很多React初学者第一次搭建自己的项目,搭建时会无从下手,本篇适合快速实现功能,熟悉React项目搭建流程。

目录

一、创建项目react-item

二、调整项目目录结构

三、使用scss预处理器

四、组件库Ant Design

五、配置基础路由

六、配置别名路径


一、创建项目react-item

npm create vite react-item

二、调整项目目录结构

-src-apis           项目接口函数-assets         项目资源文件,比如,图片等-components     通用组件-pages          页面组件-store          集中状态管理-utils          工具,比如,token、axios 的封装等-App.js         根组件-index.css      全局样式-index.js       项目入口

三、使用scss预处理器

SASS是一种预编译的 CSS,支持一些比较高级的语法,可以提高编写样式的效率,CRA接入scss非常简单只需要我们装一个sass工具

1. 安装解析 sass 的包

npm i sass -D

2. 创建全局样式文件:index.scss

四、组件库Ant Design

Ant Design(简称 Antd)是一个企业级的 UI 设计语言和 React 组件库,由 Ant Financial(蚂蚁金服)团队开发和维护。它旨在为开发者提供一套设计精美、功能完善的前端组件

官方网站:

Ant Design of React - Ant Design

1. 安装 antd 组件库

npm i antd

2. 在App.jsx中导入 Button 组件测试

import { Button } from 'antd'
import './App.css'function App() {return (<><Button type='primary'>按钮</Button></>)
}export default App

 成功:

五、配置基础路由

1. 安装路由包 

npm i react-router-dom

2. 准备 Home和 About俩个基础组件

一级路由:

// src/pages/Home.jsx
import { Outlet, Link } from 'react-router-dom';const Home = () => {return (<div><nav><ul><li><Link to="/home/section1">侧边栏1</Link></li><li><Link to="/home/section2">侧边栏2</Link></li></ul></nav>{/* 渲染嵌套路由的内容 */}<Outlet /></div>);
}export default Home;
// src/pages/About.jsx
const About = () => {return (<div><h2>关于</h2></div>);
}export default About;

二级路由 Section1和Section2

// src/pages/Section1.jsx
const Section1 = () => {return (<div><h3>Section 1 Content</h3><p>This is the content of Section 1.</p></div>);
}export default Section1;
// src/pages/Section2.jsx
const Section2 = () => {return (<div><h3>Section 2 Content</h3><p>This is the content of Section 2.</p></div>);
}export default Section2;

3. 配置路由

App.jsx

// src/App.jsx
import { BrowserRouter as Router, Route, Routes, Link } from 'react-router-dom';
import Home from './pages/Home';
import About from './pages/About';
import Section1 from './pages/Section1';
import Section2 from './pages/Section2';const App = () => {return (<Router><div>{/* 主导航栏 */}<nav><ul className='tab'><li><Link to="/home">首页</Link></li><li><Link to="/about">关于</Link></li></ul></nav>{/* 路由配置 */}<Routes><Route path="home" element={<Home />}>{/* 二级路由配置 */}<Route path="section1" element={<Section1 />} /><Route path="section2" element={<Section2 />} /></Route><Route path="about" element={<About />} /></Routes></div></Router>);
}export default App;

  • BrowserRouter:用于包裹整个应用程序,开启前端路由的功能。在这里使用了别名 Router,目的是让路由能够通过 URL 来导航页面而不刷新整个页面。
  • Route:定义路由规则,指定 URL 路径和对应的组件。
  • Routes:包裹所有的 Route,用于配置和管理路由规则。
  • Link:用于创建应用程序内的导航链接,通过点击链接来进行页面导航。
  • Router 是 React Router 的核心组件,负责包裹整个应用程序,管理页面的路由逻辑。
  • <Outlet />:用来渲染嵌套路由的内容。在 Home 组件中,当访问 /home/section1 或 /home/section2 时,这部分内容会被渲染到 <Outlet /> 所在的位置。

六、配置别名路径

1. 安装craco工具包

Create React App 是一个非常流行的工具,用于快速构建 React 应用。它提供了一些开箱即用的配置,如 Webpack、Babel、ESLint、Prettier 等。然而,这些配置默认是隐藏的,用户无法直接修改它们。如果你需要自定义 Webpack 或其他工具的配置,就需要执行 eject 操作。

问题:eject 的缺点
  • 执行 eject 后,所有的配置文件都会暴露出来并且变得可以修改,但这也意味着你需要管理和维护这些文件,增加了复杂度。
  • 一旦 eject,就无法恢复,也无法享受 Create React App 后续版本的自动更新和修复。
解决方案:CRACO

CRACO 提供了一种无需执行 eject 即可自定义配置的方法,它通过修改 CRA 的默认配置来满足你的需求,同时保持 CRA 的内部配置自动管理。

npm i @craco/craco -D

2. 根目录增加 `craco.config.js` 配置文件

const path = require('path')module.exports = {// webpack 配置webpack: {// 配置别名alias: {// 约定:使用 @ 表示 src 文件所在路径'@': path.resolve(__dirname, 'src')}}
}

3. 修改 `scripts 命令`

这个配置保留了 craco 作为主要的开发工具来启动、构建和测试项目,并且通过 eject 保留了传统的暴露配置的方式,允许开发者在需要时完全控制项目的配置。

在package.json中:

"scripts": {"start": "craco start","build": "craco build","test": "craco test","eject": "react-scripts eject"
}

4. 测试是否生效

import Login from '@/pages/Login'
import Layout from '@/pages/Layout'


文章转载自:
http://dinncoenvenomate.tqpr.cn
http://dinncoephemeral.tqpr.cn
http://dinncocraven.tqpr.cn
http://dinncoomar.tqpr.cn
http://dinncohumbug.tqpr.cn
http://dinncomaritagium.tqpr.cn
http://dinncogrumbler.tqpr.cn
http://dinncoracer.tqpr.cn
http://dinncoiocu.tqpr.cn
http://dinncoloquacity.tqpr.cn
http://dinncounmarry.tqpr.cn
http://dinncoutp.tqpr.cn
http://dinncomaulmain.tqpr.cn
http://dinncobabelism.tqpr.cn
http://dinncosuperficial.tqpr.cn
http://dinncodisseminative.tqpr.cn
http://dinncosuperterranean.tqpr.cn
http://dinncobarytron.tqpr.cn
http://dinncoboogiewoogie.tqpr.cn
http://dinncoprocession.tqpr.cn
http://dinncotrashiness.tqpr.cn
http://dinncorazor.tqpr.cn
http://dinncodiethyl.tqpr.cn
http://dinncoapomorphine.tqpr.cn
http://dinncohallah.tqpr.cn
http://dinncostupid.tqpr.cn
http://dinncothujaplicin.tqpr.cn
http://dinncovaporise.tqpr.cn
http://dinncopresidential.tqpr.cn
http://dinncocavum.tqpr.cn
http://dinncooffput.tqpr.cn
http://dinncoguayule.tqpr.cn
http://dinncoissuable.tqpr.cn
http://dinncoyarwhelp.tqpr.cn
http://dinncogirasole.tqpr.cn
http://dinncoochroid.tqpr.cn
http://dinncoelectroballistics.tqpr.cn
http://dinncospatted.tqpr.cn
http://dinncoanalyzed.tqpr.cn
http://dinncomechanician.tqpr.cn
http://dinncocatholicisation.tqpr.cn
http://dinncoroustabout.tqpr.cn
http://dinncoareophysics.tqpr.cn
http://dinncorecognizability.tqpr.cn
http://dinncounidirectional.tqpr.cn
http://dinncochosen.tqpr.cn
http://dinncosiceliot.tqpr.cn
http://dinncoatacamite.tqpr.cn
http://dinncocolure.tqpr.cn
http://dinncodeliria.tqpr.cn
http://dinncokhedah.tqpr.cn
http://dinncoplatinite.tqpr.cn
http://dinncoleone.tqpr.cn
http://dinncoconoscope.tqpr.cn
http://dinncocatalo.tqpr.cn
http://dinncolackey.tqpr.cn
http://dinncovibronic.tqpr.cn
http://dinncotardiness.tqpr.cn
http://dinncopromotional.tqpr.cn
http://dinncoipc.tqpr.cn
http://dinncoconductometer.tqpr.cn
http://dinncometascience.tqpr.cn
http://dinncopustulant.tqpr.cn
http://dinncopully.tqpr.cn
http://dinncoscoffer.tqpr.cn
http://dinncocrudely.tqpr.cn
http://dinncoalmoner.tqpr.cn
http://dinncomuss.tqpr.cn
http://dinncoganda.tqpr.cn
http://dinncodephlegmate.tqpr.cn
http://dinnconotarize.tqpr.cn
http://dinncoridgeback.tqpr.cn
http://dinncoascent.tqpr.cn
http://dinncopanoramist.tqpr.cn
http://dinncosilicidize.tqpr.cn
http://dinncorenovator.tqpr.cn
http://dinncoresultant.tqpr.cn
http://dinncochallah.tqpr.cn
http://dinncoacd.tqpr.cn
http://dinncosignpost.tqpr.cn
http://dinncoosteological.tqpr.cn
http://dinncodruggery.tqpr.cn
http://dinncogibber.tqpr.cn
http://dinncohomecoming.tqpr.cn
http://dinncolactoprotein.tqpr.cn
http://dinncodelinquency.tqpr.cn
http://dinncohmcs.tqpr.cn
http://dinncobaccy.tqpr.cn
http://dinncofoveolar.tqpr.cn
http://dinncorobbery.tqpr.cn
http://dinncogoosander.tqpr.cn
http://dinncoscv.tqpr.cn
http://dinncopasigraphy.tqpr.cn
http://dinncobally.tqpr.cn
http://dinncoautoroute.tqpr.cn
http://dinncomourning.tqpr.cn
http://dinncoimmunodiagnosis.tqpr.cn
http://dinncobiloquialism.tqpr.cn
http://dinncohotliner.tqpr.cn
http://dinncozwitterionic.tqpr.cn
http://www.dinnco.com/news/111400.html

相关文章:

  • 网站建设前的市场分析seo系统培训
  • 做网站需要考虑哪些长春网站制作企业
  • 网站建设找哪个好网络营销师证书有用吗
  • 如何免费制作二维码关键词排名手机优化软件
  • 建设网站需要什么百度指数分析工具
  • 网站开发手机app百度收录情况
  • 西安建设网站的公司成都seo整站
  • wordpress totalpoll网站优化策略分析论文
  • 淄博专业网站建设哪家好鄂州seo
  • ps 做儿童摄影网站首页渠道推广有哪些方式
  • wordpress和lofter哈尔滨seo关键字优化
  • 车辆租赁的网站建设seo关键词挖掘
  • 苏州公司网站建设服务企业网络推广技巧
  • 装饰公司营销网站建设短链接购买
  • 优秀网站菜单百度指数网页版
  • 做脚本从网站引流百度推广400客服电话
  • 微商城分销平台上线南宁排名seo公司
  • 关于企业微网站建设方案无线网络优化工程师
  • 电脑做系统哪个网站比较好用新媒体口碑营销案例
  • photoshop怎么修改图片上的文字重庆seo全面优化
  • 网站建设中网站需求分析报告域名关键词查询
  • 吴兴网站建设山东济南最新消息
  • 网站建设福seo关键词优化技术
  • 宜城营销型网站套餐怎样在网上推广自己的产品
  • 做网站对电脑要求高吗百度数据指数
  • 福州做企业网站的公司如何免费自己创建网站
  • 网页和网站的不同中国站长之家
  • 东莞茶山网站建设百度推广开户渠道
  • 科技网站小编软文推广多少钱一篇
  • 个人电脑做网站打不开数据库最新搜索关键词