Skip to content

Instantly share code, notes, and snippets.

@HiChen404

HiChen404/React Secret

Last active September 3, 2022 12:47
Show Gist options
  • Save HiChen404/850328bbf20fe27062799ea7d8703b1f to your computer and use it in GitHub Desktop.
Save HiChen404/850328bbf20fe27062799ea7d8703b1f to your computer and use it in GitHub Desktop.
React
const a = 1
@HiChen404
Copy link
Author

/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react'
import styled from '@emotion/styled'

@HiChen404
Copy link
Author

HiChen404 commented Jun 7, 2022

#Bug

关于 React 或 Vue 的部署问题

在部署上线后, 直接访问 https://xxx.com/about 或在 https://xxx.com/about 页面刷新会显示 404 错误。

这是因为如果 SPA 应用使用 history pushState ,那么必须添加一个重写规则。

解决方法:

  • 使用 Hash Router
  • 添加重写规则:
    Netlify: 在 public 目录中创建 _redirects 文件并写入 /* /index.html 200

https://docs.netlify.com/configure-builds/javascript-spas/#build-configuration-for-javascript-spas
https://stackoverflow.com/questions/58065603/netlify-renders-404-on-page-refresh-using-react-and-react-router

@HiChen404
Copy link
Author

HiChen404 commented Jun 9, 2022

#Tips

React 中使用 React.componentProps<T> 获取一个组件其属性的类型。

@HiChen404
Copy link
Author

HiChen404 commented Aug 4, 2022

#Bug #Tips

项目中遇到 ESlint 意料之中的报错,导致无法提交等情况时,可以考虑使用:

// eslint-disable-next-line 
//@ts-ignore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment