|
1
|
--- |
|
2
|
sidebar_label: "ui-route-must-have-default-export" |
|
3
|
--- |
|
4
|
|
|
5
|
export const metadata = { |
|
6
|
title: `ui-route-must-have-default-export - ESLint plugin rules`, |
|
7
|
} |
|
8
|
|
|
9
|
# {metadata.title} |
|
10
|
|
|
11
|
This rule requires UI route `page` files to default-export the React component. |
|
12
|
|
|
13
|
## Severity |
|
14
|
|
|
15
|
`error`. This rule is enabled in the [recommended](../../page.mdx#recommended) preset. |
|
16
|
|
|
17
|
## What it Targets |
|
18
|
|
|
19
|
This rule targets `page.tsx` files in your project's `src/admin/routes` directory. It reports a UI route file that doesn't have a default export. |
|
20
|
|
|
21
|
The following code is reported by the rule: |
|
22
|
|
|
23
|
```tsx title="src/admin/routes/custom/page.tsx" |
|
24
|
import { defineRouteConfig } from "@medusajs/admin-sdk" |
|
25
|
|
|
26
|
const CustomPage = () => <>Custom</> |
|
27
|
|
|
28
|
export const config = defineRouteConfig({ |
|
29
|
label: "Custom", |
|
30
|
}) |
|
31
|
|
|
32
|
export { CustomPage } |
|
33
|
``` |
|
34
|
|
|
35
|
Instead, default-export the React component: |
|
36
|
|
|
37
|
```tsx title="src/admin/routes/custom/page.tsx" |
|
38
|
import { defineRouteConfig } from "@medusajs/admin-sdk" |
|
39
|
|
|
40
|
const CustomPage = () => <>Custom</> |
|
41
|
|
|
42
|
export const config = defineRouteConfig({ |
|
43
|
label: "Custom", |
|
44
|
}) |
|
45
|
|
|
46
|
export default CustomPage |
|
47
|
``` |
|
48
|
|
|
49
|
## Why it's Important |
|
50
|
|
|
51
|
Medusa renders the default export of a `page.tsx` file as the route's page. Without a default export, the route has no component to render. |
|
52
|
|
|
53
|
Learn more in the [UI Routes documentation](!docs!/learn/fundamentals/admin/ui-routes). |
|
54
|
|
|
55
|
## Fixable |
|
56
|
|
|
57
|
This rule isn't auto-fixable. |