Nextjs似乎不可以使用Suspense
今天准备把一个异步加载的组件用Suspense
,结果似乎不行。
报错如下:
ReactDOMServer does not yet support Suspense.
后来又搜到一个帖子,看来是确定了:
https://spectrum.chat/next-js/general/suspense-support~f83c5c32-cb4d-419e-ba3d-f08948e63584
今天准备把一个异步加载的组件用Suspense
,结果似乎不行。
报错如下:
ReactDOMServer does not yet support Suspense.
后来又搜到一个帖子,看来是确定了:
https://spectrum.chat/next-js/general/suspense-support~f83c5c32-cb4d-419e-ba3d-f08948e63584
- It is rendered once on the server - it is the root of your app
- App's getInitialProps is called before anything else - even before getInitialProps in _document.js
- It is created and mounted ONLY ONCE on the client - when the page first loads. Thereafter, on page navigation, App.getInitialProps is called before each page, and then its render function is called, to render the incoming page.
首先,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),都会报错,错误信息这样的:
useRouter
用在functional component
里;withRouter
用在class component
里。