Skip to content

Commit

Permalink
docs: 📚️ added react-router hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Can-Sahin committed May 25, 2020
1 parent 0793d31 commit 3927a1b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/building-blocks/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,30 @@ export function AboutPage() {
}
```

## Routing programmatically

You can use the [react-router hooks](https://reacttraining.com/react-router/web/api/Hooks) to change the route or get params etc...

```ts
import { useHistory } from 'react-router-dom';

function HomeButton() {
let history = useHistory();

function handleClick() {
history.push('/home');
}

return (
<button type="button" onClick={handleClick}>
Go home
</button>
);
}
```

{% hint style="info" %}

You can read more in [`react-router`'s documentation](https://reacttraining.com/react-router/web/api).

{% endhint %}

0 comments on commit 3927a1b

Please sign in to comment.