react-breadcrumbs-jsonld
TypeScript icon, indicating that this package has built-in type declarations

0.1.21 • Public • Published

react-breadcrumbs-jsonld

npm version License

Overview

Dynamically generates JSON-LD structured for breadcrumbs in React.

Installation

You can install this library using npm:

npm install react-breadcrumbs-jsonld

Usage

  • url must be an absolute path.
    • Must begin with either http or https.
  • URLs must be recursively nested.

Example

import { BreadcrumbSchema, BreadcrumbItem } from "react-breadcrumbs-jsonld";

function App() {
  const breadcrumbs: BreadcrumbItem[] = [
    { url: "https://example.com/", name: "Home" },
    { url: "https://example.com/product/", name: "Products" },
    { url: "https://example.com/product/hoge", name: "Hoge" },
  ];

  return (
    <>
      <BreadcrumbSchema breadcrumbs={breadcrumbs} />
    </>
  );
}

Output

<script type="application/ld+json">
  {
    "@context": "https://schema.org",
    "@type": "BreadcrumbList",
    "itemListElement": [
      {
        "@type": "ListItem",
        "position": 1,
        "item": {
          "@id": "https://example.com/",
          "name": "Home"
        }
      },
      {
        "@type": "ListItem",
        "position": 2,
        "item": {
          "@id": "https://example.com/product/",
          "name": "Products"
        }
      },
      {
        "@type": "ListItem",
        "position": 3,
        "item": {
          "@id": "https://example.com/product/hoge",
          "name": "Hoge"
        }
      }
    ]
  }
</script>

Schema.org Test Result

Test Result

Link

License

This project is licensed under the MIT License - see the LICENSE file for details.

Package Sidebar

Install

npm i react-breadcrumbs-jsonld

Weekly Downloads

193

Version

0.1.21

License

MIT

Unpacked Size

600 kB

Total Files

22

Last publish

Collaborators

  • hidaka