Usage
Learn the basics of working with fullstack-components
.
Styling
Fullstack Components uses Tailwind as the default styling engine, but it's an optional dependency. This allows you to use whatever styling approach you prefer.
Configuring Tailwind source paths
If you're using any of the prebuilt components as-is, you need to add fullstack-components
as a content source for your project, to ensure all the Tailwind class names are included.
Customizing styles with Tailwind
When using Tailwind to customize component styles, it's recommended to use the merge
utility to safely combine CSS classes without style conflicts.
merge
combines tailwind-merge
and clsx
to allow for efficient and flexible overrides.
Quickstart
After installing, this page takes you through making a <NotFoundEnhancer>
Component that uses your sitemap to find the closest matching page to the "not found" / 404
URL.
The component also uses the contents of your website URLs to create helpful messages for visitors.
Step 1: Generate a sitemap
You need a sitemap that the <NotFoundEnhancer>
can scan in order to suggest alternative pages to navigate to.
Add a static sitemap.xml
or generate it dynamically
In Next.js 14, you can generate a sitemap.xml
in a few different ways. For this simple scenario, consider placing a static file in the app directory or using a sitemap.(js|ts)
file for dynamic generation.
Alternatively, consider using the next-sitemap
NPM package for easy sitemap creation.
Example output:
Ensure your sitemap is accessible at /sitemap.xml
in your application, and continue to the next step.
Step 2: Configure the API route handler
In the API route handler, add the following configuration to use the useNotFoundEnhancement
hook shown later.
Remember to add NEXT_PUBLIC_HOST
to your .env
file, or inline in handleNotFoundEnhancement
.
Not Found Enhancer requires configuration of the API handler route. Not all features require configuration, so read the documentation for each feature.
Step 3: Create the Client Component
The core part of the functionality is using the useNotFoundEnhancement
hook to get the data you'll need.
Step 4: Create a not-found
page
- Using the Next.js App Router: Create a
not-found.tsx
page in your app. - Using the Next.js Pages Router: Create a
404.tsx
page in your app.
Now that you've created the not-found
page and added the <NotFoundEnhancer>
, try visiting a URL in your application that doesn't exist to see it in action.
Testing it out
For example, navigate to http://localhost:3000/about-123, or any other URL that doesn't exist in your application.
If everything works correctly you'll notice how the <NotFoundEnhancer>
dynamically enhances your application's 'Not Found' page.
Keep in mind
The more pages your Next.js application has in its sitemap, the more effectively the <NotFoundEnhancer>
works, providing a richer user experience.
What's next?
Congratulations on starting your journey with Fullstack Components! 🎉
You've taken the first steps towards seamlessly integrating AI capabilities into your projects. Explore the docs to discover more features that will enhance your development experience.