Will fallback of getStaticPaths in Next.js work on Static Sites like S3 or Github Pages?
💡 IT DOESN’T WORK AT ALL AS IT DOENS’T HAVE SERVER
Since getStaticPaths, getStaticProps, and getServerSideProps require a Node server or any other server, all Pre-render functions at Build time cannot be run in AWS S3 and Github Pages where the Node server cannot be uploaded
(However, when you attempt to deploy, you will build a new build, so the latest will be applied.)
AWS Amplify, Vercel seemed appropriate for Next.js because a server for serverless is available
import React, { useEffect, useState } from "react";
const Post = (data: IData, params: IRoute) => {
const {
category: categories,
sub_category: sub_categories,
post: posts,
} = params;
if (!data) return null;
return (
<MarkdownContainer>
<div>{data}</div>
</MarkdownContainer>
);
};
export default Post;
export const getStaticPaths = async () => {
const res = await fetch("https://API_OR_SOMETHING.com/v2/get");
const data = await res.json();
const paths = data.map((el) => {
const { category, sub_category, post } = el;
return {
params: {
category,
sub_category,
post,
},
};
});
return {
paths,
fallback: true,
};
};
export const getStaticProps = ({ params }: any) => {
const res = await fetch("https://API_OR_SOMETHING.com/v2/getData");
const data = await res.json();
return {
props: {
params,
data,
},
};
};