@troyio/vite-file-router 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -12
- package/devtools/app.js +961 -143
- package/devtools/index.html +147 -33
- package/devtools/style.css +1136 -231
- package/dist/devtools-app.d.ts +59 -0
- package/dist/devtools.d.ts +50 -0
- package/dist/generator.d.ts +8 -1
- package/dist/index.d.ts +9 -3
- package/dist/index.js +413 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -326,10 +326,53 @@ export default defineConfig({
|
|
|
326
326
|
});
|
|
327
327
|
```
|
|
328
328
|
|
|
329
|
-
Open the **Routes** dock to
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
329
|
+
Open the **Routes** dock to use the panel. It's development-only and needs
|
|
330
|
+
Vite DevTools enabled. In the panel you can:
|
|
331
|
+
|
|
332
|
+
- **Browse the route tree.** Each route shows its URL segment, full path, and
|
|
333
|
+
badges for its files: page, layout, loading, error, not-found (`404`),
|
|
334
|
+
loader, and action. You can filter by path, param, or file, collapse
|
|
335
|
+
branches, and move between routes with the arrow keys.
|
|
336
|
+
- **See route details.** Select a route to see its params and files.
|
|
337
|
+
- **Open files in your editor.** Click any file path. This uses Vite's built-in
|
|
338
|
+
`/__open-in-editor` endpoint, so it opens the editor Vite detects or the one
|
|
339
|
+
named in `LAUNCH_EDITOR`.
|
|
340
|
+
- **Test a URL.** Enter a path such as `/users/42?tab=posts`. The panel shows
|
|
341
|
+
the matched routes, the params taken from the URL, and the page or
|
|
342
|
+
not-found page that renders. It also lists the layouts, loaders, loading
|
|
343
|
+
fallback, and error boundary that apply. Matching uses React Router's
|
|
344
|
+
`matchRoutes`, so the result agrees with the app. The matched routes are
|
|
345
|
+
highlighted in the tree.
|
|
346
|
+
- **Spot route conflicts.** Pages that resolve to the same URL pattern are
|
|
347
|
+
listed at the top, with links to their files.
|
|
348
|
+
- **Follow the current page.** The **Current page** card shows the URL your
|
|
349
|
+
app is on, its params, and the page that renders it. The matched routes get
|
|
350
|
+
a green dot in the tree, and the card updates as the app navigates. With
|
|
351
|
+
several app tabs open, pick which one to follow. When a tab closes, it drops
|
|
352
|
+
out of the list.
|
|
353
|
+
- **See loader and action calls.** The **Timeline** tab lists each loader and
|
|
354
|
+
action call your app makes, newest first. Each entry shows the route, URL,
|
|
355
|
+
start time, duration, and outcome: returned data, a redirect with its status
|
|
356
|
+
and location, a returned response, or a thrown error. Calls of 500 ms or
|
|
357
|
+
more are highlighted. It also shows each `shouldRevalidate` decision, so
|
|
358
|
+
you can see when a loader was skipped. You can filter by call type or text,
|
|
359
|
+
and expand an entry to see a short preview of returned data and a link to
|
|
360
|
+
the loader or action file. The dev server keeps the last 200 calls, so a
|
|
361
|
+
panel opened later still sees recent history.
|
|
362
|
+
|
|
363
|
+
The panel updates on its own when route files are added, removed, or renamed.
|
|
364
|
+
The dev server pushes changes over a Server-Sent Events stream instead of the
|
|
365
|
+
panel polling. If the dev server restarts, the panel reconnects by itself. The
|
|
366
|
+
refresh button reloads the data by hand.
|
|
367
|
+
|
|
368
|
+
The current page and the timeline come from a small client that
|
|
369
|
+
`virtual:routes` includes on the dev server only. It reports the app's URL and
|
|
370
|
+
wraps the generated loader, action, and `shouldRevalidate` handlers. It sends
|
|
371
|
+
these over Vite's HMR connection. Handler results pass through unchanged, and
|
|
372
|
+
only a short text preview of returned data is sent. It tracks navigation by
|
|
373
|
+
wrapping `history.pushState` and `history.replaceState` and listening for
|
|
374
|
+
`popstate`, and it also supports hash URLs (`#/path`). Production builds
|
|
375
|
+
include none of this code.
|
|
333
376
|
|
|
334
377
|
### Typed route helpers
|
|
335
378
|
|
|
@@ -366,26 +409,35 @@ another page's URL pattern are reported as conflicts. The generated
|
|
|
366
409
|
|
|
367
410
|
### Generated route types
|
|
368
411
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
412
|
+
In TypeScript projects, the plugin writes `src/route-types.d.ts` when the dev
|
|
413
|
+
server starts and at the start of each build. It counts a project as
|
|
414
|
+
TypeScript when the Vite project root has a `tsconfig.json` or
|
|
415
|
+
`jsconfig.json`. JavaScript projects without either file get no extra file.
|
|
416
|
+
|
|
417
|
+
The plugin rewrites the file whenever route files are added, removed, or
|
|
418
|
+
renamed, and leaves it alone when nothing changed. The file lists every
|
|
419
|
+
discovered page pattern and loader module. With it in your TypeScript project,
|
|
420
|
+
`routePath`, `routePatterns`, and the hooks below only accept routes that
|
|
421
|
+
exist, and your editor autocompletes them:
|
|
375
422
|
|
|
376
423
|
```ts
|
|
377
424
|
routePath("/users/:userId", { userId }); // OK
|
|
378
425
|
routePath("/usres/:userId", { userId }); // Type error: unknown route pattern
|
|
379
426
|
```
|
|
380
427
|
|
|
381
|
-
|
|
382
|
-
|
|
428
|
+
The `dts` option controls this. It defaults to `"auto"`, which is the behavior
|
|
429
|
+
above. A path, relative to the Vite project root and ending in `.d.ts`, always
|
|
430
|
+
writes the file there, even without a TypeScript config. `false` never writes
|
|
431
|
+
it:
|
|
383
432
|
|
|
384
433
|
```ts
|
|
385
434
|
plugins: [routes({ dts: "types/route-types.d.ts" })];
|
|
386
435
|
plugins: [routes({ dts: false })];
|
|
387
436
|
```
|
|
388
437
|
|
|
438
|
+
If your `tsconfig.json` isn't in the Vite project root, for example when Vite's
|
|
439
|
+
`root` points at a subfolder, set an explicit path.
|
|
440
|
+
|
|
389
441
|
Without the file, route patterns are typed as `string` and loader data as
|
|
390
442
|
`unknown`, the same as before. You can commit the file so types work before
|
|
391
443
|
the first dev run, or add it to `.gitignore`.
|