11// src/app/resource/[slug]/page.js
22import { resources } from '@/data/resources' ;
3- import { redirect , notFound } from 'next/navigation' ;
3+ import { notFound } from 'next/navigation' ;
44import Link from 'next/link' ;
55import {
66 FaExternalLinkAlt , FaHeart , FaDollarSign , FaQuestionCircle , FaUniversity ,
@@ -9,54 +9,35 @@ import {
99 FaUserFriends , FaCoins , FaListOl , FaUserShield , FaArrowRight
1010} from 'react-icons/fa' ;
1111
12- // THIS IS THE KEY FIX:
13- // We tell Next.js to generate a page for every slug AND every ID.
14- // This ensures that links with UUIDs do not result in a 404 error after deployment.
12+ // This now correctly tells Next.js to build a static page for every SLUG.
1513export async function generateStaticParams ( ) {
16- const paths = [ ] ;
17- resources . forEach ( resource => {
18- // Add path for the human-readable slug
19- paths . push ( { slug : resource . slug } ) ;
20- // Add path for the permanent ID
21- if ( resource . id ) {
22- paths . push ( { slug : resource . id } ) ;
23- }
24- } ) ;
25- return paths ;
14+ return resources . map ( ( resource ) => ( {
15+ slug : resource . slug ,
16+ } ) ) ;
2617}
2718
19+ // Generate metadata based solely on the SLUG.
2820export async function generateMetadata ( { params } ) {
29- const resource = resources . find ( p => p . slug === params . slug || p . id === params . slug ) ;
21+ const resource = resources . find ( p => p . slug === params . slug ) ;
3022 if ( ! resource ) {
31- return {
32- title : 'Resource Not Found' ,
33- } ;
23+ return { title : 'Resource Not Found' } ;
3424 }
3525 const title = `${ resource . title } - Yourself To Science` ;
3626 const description = resource . description || `Learn more about contributing to ${ resource . title } .` ;
3727 const canonicalUrl = `https://yourselftoscience.org/resource/${ resource . slug } ` ;
38-
28+
3929 return {
4030 title,
4131 description,
42- alternates : {
43- canonical : canonicalUrl ,
44- } ,
32+ alternates : { canonical : canonicalUrl } ,
4533 } ;
4634}
4735
4836export default function ResourcePage ( { params } ) {
49- const resource = resources . find ( p => p . slug === params . slug || p . id === params . slug ) ;
50-
37+ // Find the resource using its SLUG.
38+ const resource = resources . find ( p => p . slug === params . slug ) ;
5139 if ( ! resource ) {
52- notFound ( ) ; // Correctly show a 404 if no resource is found
53- }
54-
55- // THIS IS THE SECOND FIX:
56- // If the page was accessed via its ID, issue a permanent redirect
57- // to the canonical URL that uses the slug.
58- if ( params . slug === resource . id && resource . id !== resource . slug ) {
59- redirect ( `/resource/${ resource . slug } ` , 'replace' ) ;
40+ notFound ( ) ;
6041 }
6142
6243 // --- All of your UI code below remains untouched ---
0 commit comments