@@ -3,29 +3,31 @@ import PropTypes from "prop-types"
3
3
import { Link as GatsbyLink , navigate as gatsbyNavigate } from "gatsby"
4
4
import { IntlContextConsumer } from "./intl-context"
5
5
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 } `
11
12
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
+ }
15
20
}
16
- if ( onClick ) {
17
- onClick ( e )
18
- }
19
- }
20
21
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
+ )
29
31
30
32
Link . propTypes = {
31
33
children : PropTypes . node . isRequired ,
@@ -55,7 +57,7 @@ export const changeLocale = (language, to) => {
55
57
}
56
58
const { routed } = window . ___gatsbyIntl
57
59
58
- const removePrefix = pathname => {
60
+ const removePrefix = ( pathname ) => {
59
61
const base =
60
62
typeof __BASE_PATH__ !== `undefined` ? __BASE_PATH__ : __PATH_PREFIX__
61
63
if ( base && pathname . indexOf ( base ) === 0 ) {
@@ -64,7 +66,7 @@ export const changeLocale = (language, to) => {
64
66
return pathname
65
67
}
66
68
67
- const removeLocalePart = pathname => {
69
+ const removeLocalePart = ( pathname ) => {
68
70
if ( ! routed ) {
69
71
return pathname
70
72
}
0 commit comments