继续谈谈Next.js Routing
首先,Next.js
是个好学校,啊不,是个好框架;
其次,Next.js
的文档也不算烂,但确实有点简陋,好多都是undocumented
。
Next.js
有个feature叫做file-system routing
:
By default, Next will serve each file in/pages
under a pathname matching the filename (eg,/pages/some-file.js
is served atsite.com/some-file
.
你可以设置一个option来turn it off:
// next.config.js
module.exports = {
useFileSystemPublicRoutes: false,
}
我今天谈论的重点是这个问题:当我在Components/SomeComponenet.jsx
里使用router(不论是useRouter还是withRouter),都会报错,错误信息这样的: