I believe some developers may find it easier to start with Next.js with a simple Motoko canister backend. So here it is. I have made the nextjs-ic-starter template open source.
Feel free to run it locally and even deploy it to IC Network.
I have written a quick start guide which I am sure you can follow and get it running in 10 mins.
You can either use the Next.js dev server in http://localhost:3000 for development with hot code deploy or deploy to local DFX server running in http://localhost:8000 .
Hi, yes I do. NextJS Link is mainly for client side routing. If you export NextJS as static files and deploy to Internet Computer, it won’t work straight away because server side is all static file serving not NodeJS.
For example:
<Link href="/profile">Profile</Link>
When the user clicks on the link, the routing will happen on the browser client side and it will load but if the user reload the page /profile, it won’t work because the backend asset canister only has /proflle.html .
What I did in my project is to use “as” attribute.
In this case the client side routing will work as well as server side when the user reloads the page. What it does is to use /profile.html in browser URL bar instead of /profile.
hi, I got my nextjs frontend deployed in canister, but when I enable SSR (with getServerSideProps), it doesn’t allow to export as below: do you know how to deal with that?
You can potentially achieve similar thing through getStaticProps which is called when NextJS generates the HTML or simply use React useEffect to load the content in client side.
thanks! but it’s problem with dynamic routers. For example, if I have posts/[id].js, after exporting, it will generate /posts/[id].html, When I try to access /posts/234, I will get 404, because no 234.html under posts
my goal is sharing a post link(e.g www.abc.com/posts/234) to someone, then they can just click the link (e.g www.abc.com/posts/234) to open the specific post (234) directly without go through from a list.
I see. It’s a bit tricky since NextJS dynamic router is basically server side routing. In that case, you can try simple HTTP query parameters with NextJS router query (which is client side) then load the content from canister via React.useEffect.
I have recently updated the Github repo to the latest DFX and added a new example with Image canister. If you are interested in it, I have written a new article.
Since I received a couple of requests recently in using NextJS 13 with IC, I have updated the NextJS IC starter to use the latest version NextJS 13.3 and DFX to 0.13.1.
When using this nextjs implementation is it possible to use optimized images? I am getting errors when I try to export if when unoptimized images is false.