Skip to content

Commit 38d5fec

Browse files
committed
fix(core): fix links
1 parent dbea0e9 commit 38d5fec

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { Link as BaseLink } from 'react-router-dom'
2+
import { Link as BaseLink, NavLink as BaseNavLink } from 'react-router-dom'
33
import PageContext from './PageContext'
44

55
function computeTo(to, lang) {
@@ -9,10 +9,18 @@ function computeTo(to, lang) {
99
return to
1010
}
1111

12-
export default function Link(props) {
13-
return (
12+
function createLink(Component) {
13+
return props => (
1414
<PageContext.Consumer>
15-
{({ lang }) => <BaseLink {...props} to={computeTo(props.to, lang)} />}
15+
{pageContext => (
16+
<Component
17+
{...props}
18+
to={computeTo(props.to, pageContext ? pageContext.lang : null)}
19+
/>
20+
)}
1621
</PageContext.Consumer>
1722
)
1823
}
24+
25+
export const Link = createLink(BaseLink)
26+
export const NavLink = createLink(BaseNavLink)

packages/smooth-core/src/client/NavLink.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/smooth-core/src/router.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ export {
99
HashRouter,
1010
Router,
1111
} from 'react-router-dom'
12-
export { default as Link } from './client/Link'
13-
export { default as NavLink } from './client/NavLink'
12+
export * from './client/Link'

0 commit comments

Comments
 (0)