I've started messing around with Next JS, and I've come across my first hurdle. I am creating a page displaying a bunch of podcast episodes and I am displaying a little preview card for each podcast on the homepage. The card component looks something like this:
import React from 'react';
import Link from 'next/link';
import { kebabCase } from 'lodash';
import { format } from 'date-fns';
import TextTruncate from 'react-text-truncate';
import { Episode as EpisodeInterface } from '../../interfaces';
type Props = {
episode: EpisodeInterface;
};
const Episode: React.FunctionComponent<Props> = ({ episode }) => {
return (
<Link
href="episodes/[id]"
as={`episodes/${episode.itunes.episode}-${kebabCase(episode.title)}`}
>
<div className="group transition duration-500 cursor-pointer rounded-lg overflow-hidden shadow-lg border border-cream-darker bg-surface hover:bg-surface-hover hover:border-surface-hover hover:text-text-hover">
<div className="px-6 py-6">
<div className="font-bold font-serif text-3xl mb-2">
{episode.title}
</div>
<div className="transition duration-500 flex justify-between mb-2 text-gray-700 group-hover:text-text-hover">
<span>Episode {episode.itunes.episode}</span>
<span>{format(new Date(episode.isoDate), 'd MMMM yyyy')}</span>
</div>
<div className="mb-2">
<TextTruncate line={3} text={episode.contentSnippet} />
</div>
</div>
</div>
</Link>
);
};
export default Episode;
Now I want to be able to pass the episode
object to the full episode page located at /pages/episodes/[id].tsx
that is being linked to via the Link
element above, rather than have to refetch and filter all the episodes based upon the name of the route that I've chosen episodes/${episode.itunes.episode}-${kebabCase(episode.title)}
.
- Is it possible to pass the entire
episode
object to the new view? - If not, is it possible to pass some more specific data (e.g. unique id) to the view that will enable me to better identify the episode without cluttering the route with query params?