I know, I know. It's new. It just came out yesterday. I recently set up a Next.js 12 app and felt confident I could get Slicemachine running on a Next.js 13 app with the new nested Layouts feature. Here's how you can do it in a nut shell:
- Run
npx create-next-app@latest --experimental-app - Follow the documentation for Set up Prismic
- When you get to
npm install @prismicio/nextyou'll need to runnpm install @prismicio/next --forcedue to strict Next.js dependency versions - Continue to configure
- Adding the
PrismicProviderandPrismicPreviewgo on theapp/layout.tsxfileβ -
Create Slice Simulator page in
app/folder - Update
next.config.jsto includebasePath: '/app',β this tells Prismic to look in theappfolder - Update the
app/page.tsxto include theSliceZoneβ β
Technically β that's as I far as I've have gotten. npm run dev works, so does npm runs slicemachine. I went further to see if I could migrate an existing project to this new repository...
I moved the Next.js 12 working apps .slicemachine folder, slices folder and updated the prismicio.js file to ensure proper routes. With that I re-ran npm run slicemachine. All my Slices showed up! None of my Custom Types showed up β haha. So running npm run dev and going to the home page naturally 404's. I assume that is because Slicemachine is not properly seeing the .slicemachine/customtypes/homepage Custom Type I made. Bummer. Can't seem to find any help on the community here that shows how to migrate an existing Next.js repository to a new repo. Will continue to try in free time! Any ideas? Feel free to share!
β
"use client";
import Link from 'next/link';
import { PrismicProvider } from '@prismicio/react';
import { PrismicPreview } from '@prismicio/next';
import { linkResolver, repositoryName } from '../prismicio';
import './globals.css'
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<PrismicProvider
linkResolver={linkResolver}
internalLinkComponent={({ href, ...props }) => (
<Link href={href}>
<a {...props} />
</Link>
)}
>
<html lang="en">
<head>
<title>Ascent Design System</title>
...
</head>
<body>
<PrismicPreview repositoryName={repositoryName}>
{children}
</PrismicPreview>
</body>
</html>
</PrismicProvider>
)
}
β β
"use client";
import { SliceZone } from '@prismicio/react';
import { components } from '../slices';
export default function Home({ page }) {
return (
<SliceZone slices={page.data.slices} components={components} />
)
}