@@ -3,20 +3,31 @@ description: |
33 Routes are the basic building block of Fresh applications. They are used to define the behaviour the application when a given path is requested.
44---
55
6- Fresh ships with the ` fsRoutes ` helper which automatically adds routes based on
7- the structure in the ` routes/ ` folder in your project. When you add a new file
8- there, it will register a new route automatically.
6+ Use the ` .fsRoutes() ` helper on the [ ` App ` ] ( /docs/canary/concepts/app ) instance
7+ to specify where file based routes should be inserted. It adds routes based on
8+ the structure in the ` routes/ ` folder in your project (or any other folder you
9+ have set in ` dev.ts ` ). When you add a new file there, it will register a new
10+ route automatically.
11+
12+ ``` ts main.ts
13+ import { Builder } from " fresh/dev" ;
14+
15+ // Optionally set a custom route dir (will be `<root>/routes` by default)
16+ const builder = new Builder ({ routeDir: " path/to/routes" });
17+
18+ if (Deno .args .includes (" build" )) {
19+ await builder .build ();
20+ } else {
21+ await builder .listen (() => import (" ./main.ts" ));
22+ }
23+ ```
924
10- ``` ts
11- import { App , fsRoutes , staticFiles } from " fresh" ;
25+ ``` ts main.ts
26+ import { App , staticFiles } from " fresh" ;
1227
1328const app = new App ({ root: import .meta .url })
14- .use (staticFiles ());
15-
16- await fsRoutes (app , {
17- loadIsland : (path ) => import (` ./islands/${path } ` ),
18- loadRoute : (path ) => import (` ./routes/${path } ` ),
19- });
29+ .use (staticFiles ())
30+ .fsRoutes (); // This inserts all file based routes here
2031```
2132
2233> [ info] : The ` staticFiles() ` middleware is required when using file based
@@ -26,6 +37,9 @@ await fsRoutes(app, {
2637Example project structure:
2738
2839``` sh Project structure
40+ ├── deno.json
41+ ├── main.ts
42+ ├── dev.ts
2943└── routes
3044 ├── (marketing) # Route group, used to group related routes
3145 │ ├── _layout.tsx # Apply layout to all routes in this directory
0 commit comments