@@ -3,29 +3,31 @@ import PropTypes from "prop-types"
33import { Link as GatsbyLink , navigate as gatsbyNavigate } from "gatsby"
44import { IntlContextConsumer } from "./intl-context"
55
6- const Link = React . forwardRef ( ( { to, language, children, onClick, ...rest } , ref ) => (
7- < IntlContextConsumer >
8- { intl => {
9- const languageLink = language || intl . language
10- const link = intl . routed || language ? `/${ languageLink } ${ to } ` : `${ to } `
6+ const Link = React . forwardRef (
7+ ( { to, language, children, onClick, ...rest } , ref ) => (
8+ < IntlContextConsumer >
9+ { ( intl ) => {
10+ const languageLink = language || intl . language
11+ const link = intl . routed || language ? `/${ languageLink } ${ to } ` : `${ to } `
1112
12- const handleClick = e => {
13- if ( language ) {
14- localStorage . setItem ( "gatsby-intl-language" , language )
13+ const handleClick = ( e ) => {
14+ if ( language ) {
15+ localStorage . setItem ( "gatsby-intl-language" , language )
16+ }
17+ if ( onClick ) {
18+ onClick ( e )
19+ }
1520 }
16- if ( onClick ) {
17- onClick ( e )
18- }
19- }
2021
21- return (
22- < GatsbyLink { ...rest } to = { link } onClick = { handleClick } ref = { ref } >
23- { children }
24- </ GatsbyLink >
25- )
26- } }
27- </ IntlContextConsumer >
28- ) )
22+ return (
23+ < GatsbyLink { ...rest } to = { link } onClick = { handleClick } ref = { ref } >
24+ { children }
25+ </ GatsbyLink >
26+ )
27+ } }
28+ </ IntlContextConsumer >
29+ )
30+ )
2931
3032Link . propTypes = {
3133 children : PropTypes . node . isRequired ,
@@ -55,7 +57,7 @@ export const changeLocale = (language, to) => {
5557 }
5658 const { routed } = window . ___gatsbyIntl
5759
58- const removePrefix = pathname => {
60+ const removePrefix = ( pathname ) => {
5961 const base =
6062 typeof __BASE_PATH__ !== `undefined` ? __BASE_PATH__ : __PATH_PREFIX__
6163 if ( base && pathname . indexOf ( base ) === 0 ) {
@@ -64,7 +66,7 @@ export const changeLocale = (language, to) => {
6466 return pathname
6567 }
6668
67- const removeLocalePart = pathname => {
69+ const removeLocalePart = ( pathname ) => {
6870 if ( ! routed ) {
6971 return pathname
7072 }
0 commit comments