Skip to content

Commit

Permalink
docs(link): provide wrapper for react router links
Browse files Browse the repository at this point in the history
  • Loading branch information
theetrain committed Aug 17, 2017
1 parent b4e2e6d commit 1e6178a
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/components/Link/Link.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,44 @@ const PurpleBlock = require('../__docs__/PurpleBlock').default;
</PurpleBlock>
```

### React Router Links (for SPAs)
### Using with React Router Links

When using Link with React Router, you must pass in the React Router Link component as a prop. It is recommended to set up a component wrapper in your project to avoid repetition, like so:

**linkwrapper.jsx**
```jsx
const React = require('react')
const ReactRouterLinkV3 = require('react-router').Link
// const ReactRouterLinkV4 = require('react-router-dom').Link
const Link = require('@telusdigital/tds').Link

const ReactRouterLink = ReactRouterLinkV3

const LinkWrapper = ({ children, ...rest }) => (
React.createElement(
Link,
{
reactRouterLinkComponent: rest.to ? ReactRouterLink : undefined,
...rest
}
children
)
)

export default LinkWrapper
```

**app.js**
```jsx
const Link = require('linkwrapper')

const MyApp = () => (
<main>
...
<Link to="/more">Read More</Link>
<Link href="https://www.telus.com/">Telus Website</Link>
</main>
)
```

When using Link with React Router, you must pass in the React Router Link component as a prop.
This way, you can output normal anchors or react router links using a single component.

0 comments on commit 1e6178a

Please sign in to comment.