You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: decisions/0011-routes-ts.md
-10
Original file line number
Diff line number
Diff line change
@@ -48,16 +48,6 @@ Remix ships with a default set of file system routing conventions. While conveni
48
48
49
49
Any project using the Vite plugin must have a `routes.ts` file which exports an array of route config objects.
50
50
51
-
### Route config is exported via the `routes` export
52
-
53
-
We specifically chose to use the `routes` export instead of the more traditional `default` export you might expect in a config file. There are a couple of reasons for this:
54
-
55
-
1. The `RouteConfig` type can be annotated up-front and inline (`export const routes: RouteConfig = [...]`).
56
-
57
-
In contrast, default exports either require a variable to be declared first (`let routes: RouteConfig = ...; export default routes;`), or they require the use of a `satisfies` annotation at the _end_ of the file (`export default ... satisfies RouteConfig`) which can be easy to miss when dealing with large route configs.
58
-
59
-
2. In other areas of the framework we've come to prefer using named exports. We want to avoid introducing many different default exports that mean different things in different contexts. Named exports are much more self-documenting when looking at the file contents alone, especially if additional exports are added in the future.
This will look for routes in the `app/routes` directory by default, but this can be configured via the `rootDirectory` option which is relative to your app directory:
@@ -29,9 +29,9 @@ This will look for routes in the `app/routes` directory by default, but this can
If you prefer to define your routes via file naming conventions rather than configuration, the `@react-router/fs-routes` package provides a [file system routing convention.][file-route-conventions]
@@ -90,14 +93,14 @@ import {
90
93
index,
91
94
} from"@react-router/dev/routes";
92
95
93
-
exportconst routes:RouteConfig= [
96
+
exportdefault [
94
97
// parent route
95
98
route("dashboard", "./dashboard.tsx", [
96
99
// child routes
97
100
index("./home.tsx"),
98
101
route("settings", "./settings.tsx"),
99
102
]),
100
-
];
103
+
]satisfiesRouteConfig;
101
104
```
102
105
103
106
The path of the parent is automatically included in the child, so this config creates both `"/dashboard"` and `"/dashboard/settings"` URLs.
0 commit comments