@spoolcms/nextjs
Version:
The beautiful headless CMS for Next.js developers
74 lines (58 loc) • 1.82 kB
JavaScript
// Example: Using Spool redirects in next.config.js
// This shows how to integrate Spool's redirect management with Next.js
import { generateSpoolRedirects } from '@spoolcms/nextjs';
/** @type {import('next').NextConfig} */
const nextConfig = {
// Your existing Next.js configuration...
async redirects() {
try {
// Fetch all redirects from Spool CMS
const spoolRedirects = await generateSpoolRedirects();
console.log(`✅ Loaded ${spoolRedirects.length} redirects from Spool CMS`);
// You can combine Spool redirects with manual ones
const manualRedirects = [
{
source: '/old-contact',
destination: '/contact',
permanent: true,
},
{
source: '/legacy/:path*',
destination: '/new/:path*',
permanent: true,
},
];
// Return combined redirects
return [...spoolRedirects, ...manualRedirects];
} catch (error) {
console.warn('Failed to load Spool redirects:', error.message);
// Return empty array to prevent build failures
// Your manual redirects can still work
return [
{
source: '/old-contact',
destination: '/contact',
permanent: true,
},
];
}
},
// Your other Next.js config...
};
export default nextConfig;
/*
Example redirects you might create in Spool admin:
1. Simple redirect:
Source: /old-about
Destination: /about
2. Blog migration:
Source: /articles/*
Destination: /blog/*
3. Product catalog restructure:
Source: /products/category/*
Destination: /shop/*
4. External redirect:
Source: /docs
Destination: https://docs.example.com
These will automatically become Next.js redirects with 301 status codes!
*/