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

React简单入门 - [Next.js项目] - 页面跳转、AntD组件、二级目录等

须知

1Next.js 官网(英文)https://nextjs.org/
2Next.js 文档(中文)https://nextjscn.org/docs/
3Ant Design组件总览https://ant-design.antgroup.com/components/overview-cn
4tailwindcss类名大全 · 官网

https://www.tailwindcss.cn/docs/justify-content

5tailwindcss常用类名https://blog.csdn.net/delete_you/article/details/129965712
1参考项目 - Nextjs构建的电子商务应用程序 (Ecommerce-2023)
2参考项目 - 12个快速学会 NextJS 的 Github 仓库

react v19和antd诸多冲突,建议回退next.js v14 (配套react v18)

npx create-next-app@14.2.20

实现目标

0. 添加二级目录 - 项目打包后运行在https://xx.com/sub-folder/

1. 应用内页面跳转

2. 简单路由

3. 集成UI组件AntD

4. 在Next.js+AppRouter环境下使用AntD的子组件 (如Input下的TextArea) 

5. 穿透antd组件,修改css,“:global”的使用方法

6. 页面变量,点击事件,请求处理

7. 变量导致的报错"It only works in a Client Component but none of its parents are marked with “use client“"

8. AntD的按钮button绑定onClick后无限死循环 - 报错 - unhandledRejection: Error: Too many re-renders. React limits the number of renders to prevent an infinite loop.

9. AntD顶部通知 滚动通知 警告实现 alert message notice

10. Next.js报错 SSR导致的问题 “Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used”

11. Next.js报错 react19的error “intercept-console-error.js:56 Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release. error@intercept-console-error.js:56”

12. axios请求 / ajax请求

13. utils/fns实现

14. antd系列“card”卡片组件右上角副标题怎么自定义不同按钮 extra对象数组

15. React的显示隐藏控制 (v-if v-show)

16. nextjs build关闭eslint

17. React的复制功能 - 复制到剪切板 - copy

版本

  "dependencies": {

    "@ant-design/icons": "^5.5.2",

    "@ant-design/nextjs-registry": "^1.0.2",

    "antd": "^5.22.4",

    "axios": "^1.7.9",

    "next": "14.2.20",

    "react": "^18",

    "react-dom": "^18"

  },

  "devDependencies": {

    "@types/node": "^20",

    "@types/react": "^18",

    "@types/react-dom": "^18",

    "eslint": "^8",

    "eslint-config-next": "14.2.20",

    "postcss": "^8",

    "tailwindcss": "^3.4.1",

    "typescript": "^5"

  }

具体操作

0. 添加二级目录 - 项目打包后运行在https://xx.com/sub-folder/

参考 https://next.nodejs.cn/docs/app/api-reference/config/next-config-js/basePath

修改/next.config.ts,在nextConfig中写入 basePath: '/sub-folder'

1. 应用内页面跳转

import Link from 'next/link'
<Link href="/my">我的</Link>

应用外链接,可以用<a href="...">xx</a>
https://nextjscn.org/docs/app/building-your-application/routing/linking-and-navigating#link-组件

2. 简单路由

Next.js 基本路由跳转:

路由结构
https://nextjscn.org/docs/app/building-your-application/routing/defining-routes
例如:
应用首页 = /app/page.jsx 【后缀可以是jsx或者tsx】
个人首页 = /app/my/page.jsx 
个人订单 = /app/my/order/page.jsx 
那么,跳转方式就是
<Link href="/my">我的</Link>
<Link href="/my/order">我的订单</Link>

3. 集成UI组件AntD

参考 https://ant-design.antgroup.com/docs/react/use-with-next-cn

1. 安装antd组件
npm install antd --save2. 使用antd组件 - (修改/app/*/page.tsx 或jsx)
import { Button } from 'antd';
嵌套<Button type="primary">Button</Button>3. 特别注意!
如果使用了App Router,需要安装“nextjs-registry”:
npm install @ant-design/nextjs-registry --save
然后修改app/layout.tsx:
import { AntdRegistry } from '@ant-design/nextjs-registry';
将{children}使用此标签嵌套,例如:
<AntdRegistry>{children}</AntdRegistry>

AntD组件大全: 组件总览 - Ant Design

4. 在Next.js+AppRouter环境下使用AntD的子组件 (

http://www.lryc.cn/news/502444.html

相关文章:

  • Redis安装和Python练习(Windows11 + Python3.X + Pycharm社区版)
  • Sqoop脚本编写(Mysql---->>hdfs)
  • 帝可得项目redis连接不上
  • JS中this的值详细讲解以及面试指向练习
  • 显示浮动式窗口的方法
  • FireFox火狐浏览器企业策略禁止更新
  • C++类的运算符重载
  • 泷羽Sec学习笔记-zmap搭建炮台
  • 分析M0G突破后急剧下跌内因,x.game阐述不利面延续多久
  • 网络爬虫全解析
  • 《孤岛惊魂4》无法启动提示缺少“msvcp100.dll”快速修复方法!
  • GS-SLAM论文阅读--RGBDS-SLAM
  • 条件编译->enable_if和 if constexpr使用区别
  • 介绍一下CSS中伪类和伪元素的概念
  • 【橘子ES】熔断器Circuit breaker
  • 6.4 CPU性能分析--Intel处理器跟踪技术
  • 期权懂|如何用第三方平台开通期权?
  • JS中const有没有变量提升
  • Axure RP全面介绍:功能、应用与中文替代方案
  • WordPress用户首次登录强制修改密码
  • AI开源南京分享会回顾录
  • 基于事件驱动的websocket简单实现
  • 【leetcode100】反转链表
  • 禅道Bug的一次迁移
  • c段和旁站讲解(附查询网址)
  • Linux编译Kernel时的文件zImage、文件dtb(dtbs)、核心模块分别是什么东西?
  • 【深度学习】深刻理解“变形金刚”——Transformer
  • 75_pandas.DataFrame 中查看和复制
  • 打电话玩手机识别-支持YOLO,COCO,VOC格式的标记,超高识别率可检测到手持打电话, 非接触式打电话,玩手机自拍等
  • 生产慎用之调试日志对空间矢量数据批量插入的性能影响-以MybatisPlus为例