Rendering Patterns
getStaticProps()
函式getStaticProps
是一個 async
函式, 利用這個函式跟外部Database獲取資料, 另一方面, 有getStaticProps
函式 Next.js 就會知道要先跟外部要資料成功後, 再把資料塞進 props
render htmlgetStaticProps
只會在sever-side被執行, 不會在client-side被執行, 所以不會被打包傳進client-side的JS檔getStaticPaths
可以事先定義哪些單獨頁面需要產生 HTML 檔案getStaticPaths()
函式getStaticPaths
是一個 async
函式回傳值包含兩個 key,分別是 paths 與 fallbackgetStaticPaths
把所有 dynamic routes 的 key 透過 paths 傳入 getStaticProps
getStaticProps
透過 paths 取得 params 的參數來取得該頁面的資料內容正如討論的,SSG有好的performance(縮短TTFB)和SEO(回應給client-side已經build好的html),在評估 SSG 對特定應用的適用性時,需要考慮以下因素:
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing