npm run dev
or yarn dev
This is catch all route.
This optional catch route.
getStaticProps
andgetStaticPaths
are executed at build time before React component. What this means is that you can use State management withingetStaticPath
to insert or load data from Flux store.
getStaticPath
(Fetches path) -> getStaticProp
(Passes path data to prop) -> Render the React Component
Next Provie
preview.ts
: Set Cookie and Preview Mode
export default (req, res: NextApiResponse) => {
// set Cookie for Preview Mode
res.setPreviewData({}) // Add TTL for cookie TTL
// Redirect user back to Preview Page
res.redirect(req.query.route)
}
clear-preview.ts
: Clear Cookie
export default (req, res: NextApiResponse) => {
res.clearPreviewData()
res.end('Preview Mode Disabled')
}
index.tsx
Root blog has ctx
(context) which has preview variable
[slug].tsx
Has Preview Variable
API GET /api/preview?route=<path>
: Set the Path as Preview Mode
API GET /api/clear-preview
: Clear Cookie for all paths
Using NextAuth library
- API State: React Hooks + (SWR || React Query)
- Application State: Use
useReducer
+ Context API