Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created October 25, 2018 21:23
Show Gist options
  • Save ryanflorence/d659b7be29d111550fb5421b80bcef2d to your computer and use it in GitHub Desktop.
Save ryanflorence/d659b7be29d111550fb5421b80bcef2d to your computer and use it in GitHub Desktop.
import React from "react";
import {
useRouter,
Link
} from "@reach/router/unstable-hooks";
function Accounts() {
let route = useRouter({
".": () => <div>boring Accounts</div>,
dope: () => <div>Dope Accounts</div>
});
return (
<div>
<h2>Accounts</h2>
<nav>
<Link to="/accounts">Accounts Home</Link> •{" "}
<Link to="/accounts/dope">
Dope Accounts
</Link>
</nav>
{route}
</div>
);
}
function App() {
let route = useRouter({
".": () => <div>Home</div>,
"invoice/:invoiceId": ({ invoiceId }) => (
<div>Invoice {invoiceId}</div>
),
"accounts/*": () => <Accounts />
});
return (
<div style={{ padding: 20 }}>
<nav>
<Link to="/">Home</Link> •{" "}
<Link to="/accounts">Accounts</Link> •{" "}
<Link to="/invoice/123">Invoice 123</Link> •{" "}
<Link to="/accounts/dope">
Dope Accounts
</Link>
</nav>
<hr />
<main tabIndex="-1">
{route}
</main>
</div>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment