-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'staging' into tx-css-lines
- Loading branch information
Showing
72 changed files
with
822 additions
and
701 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## Typed Routes | ||
|
||
The explorer uses some enhancements to `react-router` to provide type checking to routes. | ||
|
||
### `RouteDefinition` | ||
|
||
`useRouteParams` and `RouteLink` take these objects to provide type checking for params. | ||
|
||
In the future these objects can provide a common way to support legacy routes. | ||
|
||
ex. | ||
``` | ||
export const ACCOUNT_ROUTE: RouteDefinition<{ | ||
id?: string | ||
tab?: 'assets' | 'transactions' | ||
assetType?: 'issued' | 'nfts' | ||
}> = { | ||
path: '/accounts/:id?/:tab?/:assetType?', | ||
} | ||
``` | ||
|
||
### `useRouteParams` | ||
|
||
A new hook which takes a `RouteDefinition` and wraps `react-router`'s `useRouteParams`. This will derive the type of the params from the definition. | ||
|
||
ex. `const { id = '', assetType = 'issued' } = useRouteParams(ACCOUNT_ROUTE)` | ||
|
||
### `RouteLink` | ||
|
||
A wrapper for `react-router`'s `Link` that takes a `RouteDefinition` and an object of params that will be type checked. | ||
|
||
Ex. `<RouteLink to={ACCOUNT_ROUTE} params={{ id: owner }}>{owner}</RouteLink>` | ||
|
||
Example that will fail to compile `<RouteLink to={ACCOUNT_ROUTE} params={{ something: owner }}>{owner}</RouteLink>` |
Oops, something went wrong.