Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

Breadcrumbs.tsx 1.2 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  1. import cx from 'classnames'
  2. import { useRouter } from 'next/router'
  3. import { useMainContext } from './context/MainContext'
  4. import { Link } from 'components/Link'
  5. export type BreadcrumbT = {
  6. title: string
  7. documentType?: string
  8. href?: string
  9. }
  10. type Props = {}
  11. export const Breadcrumbs = (props: Props) => {
  12. const router = useRouter()
  13. const pathWithLocale = `/${router.locale}${router.asPath.split('?')[0]}` // remove query string
  14. const { breadcrumbs } = useMainContext()
  15. return (
  16. <nav className="breadcrumbs f5" aria-label="Breadcrumb">
  17. {Object.values(breadcrumbs).map((breadcrumb) => {
  18. if (!breadcrumb) {
  19. return null
  20. }
  21. const title = `${breadcrumb.documentType}: ${breadcrumb.title}`
  22. return !breadcrumb.href ? (
  23. <span key={title} title={title}>
  24. {breadcrumb.title}
  25. </span>
  26. ) : (
  27. <Link
  28. key={title}
  29. href={breadcrumb.href}
  30. title={title}
  31. className={cx(
  32. 'd-inline-block',
  33. pathWithLocale === breadcrumb.href && 'color-text-tertiary'
  34. )}
  35. >
  36. {breadcrumb.title}
  37. </Link>
  38. )
  39. })}
  40. </nav>
  41. )
  42. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...