Skip to content

Commit cf8ab5f

Browse files
authored
Merge pull request #5860 from jgabriele/master
[Doc] Add documentation for `linkToRecord`
2 parents 0deb2b5 + 69706ef commit cf8ab5f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

docs/Fields.md

+15
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,21 @@ export const UserList = (props) => (
15241524

15251525
**Tip**: In such custom fields, the `source` is optional. React-admin uses it to determine which column to use for sorting when the column header is clicked. In case you use the `source` property for additional purposes, the sorting can be overridden by the `sortBy` property on any `Field` component.
15261526

1527+
### Linking to other records
1528+
1529+
Your custom Field component might need to display a link to another record. React Admin provides a `linkToRecord(basePath, id[, linkType])` method for this purpose.
1530+
1531+
```js
1532+
import { linkToRecord } from 'react-admin';
1533+
import { Link } from 'react-router-dom';
1534+
1535+
const MyCustomField = ({ record: post }) => {
1536+
const linkToUser = linkToRecord('/users', post.user_id, 'show');
1537+
1538+
return <Link to={linkToUser}>{seller.username}</Link>;
1539+
};
1540+
```
1541+
15271542
## Third-Party Components
15281543

15291544
You can find components for react-admin in third-party repositories.

docs/Reference.md

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ title: "Reference"
140140
* `<TopToolbar>`
141141
* [`<UrlField>`](./Fields.md#urlfield)
142142
* [`<WizardForm>`](https://marmelab.com/ra-enterprise/modules/ra-form-layout#wizardform)<img class="icon" src="./img/premium.svg" />
143+
* [`linkToRecord`](./Fields.md#linking-to-other-records)
143144
* [`useAppLocationState`](https://marmelab.com/ra-enterprise/modules/ra-navigation#useapplocationstate-retrieve-and-define-app-location)<img class="icon" src="./img/premium.svg" />
144145
* [`useAppLocationMatcher`](https://marmelab.com/ra-enterprise/modules/ra-navigation#useapplocationmatcher-apply-a-matching-on-the-current-app-location)<img class="icon" src="./img/premium.svg" />
145146
* [`useAuthenticated`](./Authentication.md#useauthenticated-hook)

0 commit comments

Comments
 (0)