Skip to content

Instantly share code, notes, and snippets.

@tak-dcxi
Last active December 2, 2021 17:11
Show Gist options
  • Save tak-dcxi/8033e30b34161c5c948dfd499b67262c to your computer and use it in GitHub Desktop.
Save tak-dcxi/8033e30b34161c5c948dfd499b67262c to your computer and use it in GitHub Desktop.
Next.jsにおけるパンくずリストの実装例
import React from 'react'
import Link from 'next/link'
type PageBreadcrumbsPropsType = {
lists: { [key: string]: string }[]
}
export const PageBreadcrumbs: React.VFC<PageBreadcrumbsPropsType> = ({ lists }) => {
return (
<nav aria-label="現在位置">
<ol itemScope itemType="http://schema.org/BreadcrumbList">
{lists.map(({ string, path }, index: number) => (
<li key={index} itemProp="itemListElement" itemScope itemType="http://schema.org/ListItem">
{lists.length - 1 !== index ? (
<>
<Link href={path} passHref>
<a itemProp="item">
<span itemProp="name">{string}</span>
</a>
</Link>
<span role="img" aria-hidden="true">&gt;</span>
<meta itemProp="position" content={`${index + 1}`} />
</>
) : (
<>
<span itemProp="item" aria-current="location">
<span itemProp="name">{string}</span>
</span>
<meta itemProp="position" content={`${index + 1}`} />
</>
)}
</li>
))}
</ol>
</nav>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment