Skip to content

Commit

Permalink
Merge branch 'staging' into tx-css-lines
Browse files Browse the repository at this point in the history
  • Loading branch information
mvadari authored Jul 7, 2023
2 parents 3f362bb + 345de6a commit 7aaca0d
Show file tree
Hide file tree
Showing 72 changed files with 822 additions and 701 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ If you are interested in adding more translations please follow the guide on [ho

## Additional Documentation
* [How to define transactions](./src/containers/shared/components/Transaction/README.md)
* [Routing](./docs/routing.md)

## React Documentation

Expand Down
34 changes: 34 additions & 0 deletions docs/routing.md
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>`
Loading

0 comments on commit 7aaca0d

Please sign in to comment.