最近在研究 ChatGPT-Next-Web 项目,是由nextjs实现的,随手分享一些关于nextjs的手记
文档:
Building Your Application: Routing | Next.js (nextjs.org)
前端项目git提交时做代码规范验证:
需要使用到的插件:
husky ,是一个 Git Hook 工具,为 git 客户端增加 hook 的。
lint-staged ,在git提交前,进行代码规则检查确保入库的代码都符合代码规则,如果对整个项目进行lint这样速度太慢,lint-staged 可以让lint 只检测暂存区的文件,提高检测速度。
window.location.search为空的解决办法
原因:
例1: ‘http://a.a.com/data?id=1&time=2021-11-23’
此时通过 window.location.search 能够正常获取到url中的查询参数 ?id=1&time=2021-11-23
例2:‘http://a.a.com/#/data?id=1&time=2021-11-23’
此时通过 window.location.search 获取到的参数为空"",这是因为使用了hash导致,因为hash会将url中第一个#后的内容都作为hash内容,所以search为空了.
解决办法1:把#去掉
解决方法2:用 window.location.hash.split("?")[1];
var search = window.location.hash.split("?")[1];
console.log(search) //id=1&time=2021-11-23