-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(Link): add react router example
- Loading branch information
Uladzimir Havenchyk
committed
Aug 19, 2019
1 parent
752b1ab
commit 9283e79
Showing
6 changed files
with
174 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React, { ComponentProps } from 'react' | ||
import { Link as PicassoLink } from '@toptal/picasso' | ||
import { | ||
Link as RouterLink, | ||
Route, | ||
Switch, | ||
LinkProps as RouterLinkProps, | ||
BrowserRouter | ||
} from 'react-router-dom' | ||
|
||
type PicassoRouterLink = RouterLinkProps & ComponentProps<typeof PicassoLink> | ||
|
||
// eslint-disable-next-line react/display-name | ||
const Link = React.forwardRef<HTMLAnchorElement, PicassoRouterLink>( | ||
function Link(props, ref) { | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
return <PicassoLink innerRef={ref} {...props} as={RouterLink} /> | ||
} | ||
) | ||
|
||
function Index() { | ||
return <h2>Home</h2> | ||
} | ||
|
||
function About() { | ||
return <h2>About</h2> | ||
} | ||
|
||
function Users() { | ||
return <h2>Users</h2> | ||
} | ||
|
||
const RoutingExample = () => { | ||
return ( | ||
<BrowserRouter> | ||
<div> | ||
<nav> | ||
<ul> | ||
<li> | ||
<Link underline='always' to='/'> | ||
Home | ||
</Link> | ||
</li> | ||
<li> | ||
<Link underline='always' to='/about'> | ||
About | ||
</Link> | ||
</li> | ||
<li> | ||
<Link underline='always' to='/users'> | ||
Users | ||
</Link> | ||
</li> | ||
</ul> | ||
</nav> | ||
<Switch> | ||
<Route path='/' exact component={Index} /> | ||
<Route path='/about/' component={About} /> | ||
<Route path='/users/' component={Users} /> | ||
<Route component={Index} /> | ||
</Switch> | ||
</div> | ||
</BrowserRouter> | ||
) | ||
} | ||
|
||
export default RoutingExample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters