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

Link.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
  1. import NextLink from 'next/link'
  2. import { ComponentProps } from 'react'
  3. import { useMainContext } from 'components/context/MainContext'
  4. const { NODE_ENV } = process.env
  5. const enableNextLinks = false
  6. type Props = { locale?: string } & ComponentProps<'a'>
  7. export function Link(props: Props) {
  8. const { airGap } = useMainContext()
  9. const { href, locale, ...restProps } = props
  10. if (!href && NODE_ENV !== 'production') {
  11. console.warn('Missing href on Link')
  12. }
  13. const isExternal = href?.startsWith('http') || href?.startsWith('//')
  14. // In airgap mode, add a tooltip to external links warning they may not work.
  15. if (airGap && isExternal) {
  16. if (restProps.className) {
  17. restProps.className += ' tooltipped'
  18. } else {
  19. restProps.className = 'tooltipped'
  20. }
  21. restProps['aria-label'] = 'This link may not work in this environment.'
  22. }
  23. if (enableNextLinks) {
  24. return (
  25. <NextLink href={href || ''} locale={locale}>
  26. <a rel={isExternal ? 'noopener' : ''} {...restProps} />
  27. </NextLink>
  28. )
  29. }
  30. return (
  31. <a
  32. href={locale ? `/${locale}${href}` : href}
  33. rel={isExternal ? 'noopener' : ''}
  34. {...restProps}
  35. />
  36. )
  37. }
Tip!

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

Comments

Loading...