aaex-file-router 1.7.5 → 1.8.0

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 CHANGED
@@ -2,8 +2,10 @@
2
2
 
3
3
  A file-based routing system for React projects that automatically generates routes from your file structure. Similar to Next.js App Router or Remix file conventions.
4
4
 
5
- ## V. 1.7.5
6
- Removed the 404 and root layout support since it was implemented wrong and broke
5
+ ## V. 1.8.0
6
+
7
+ Added [useScroll hook](#useScroll) to help with page scroll after navigation
8
+
7
9
  ## Table of Contents
8
10
 
9
11
  - [Features](#features)
@@ -19,6 +21,7 @@ Removed the 404 and root layout support since it was implemented wrong and broke
19
21
  - [Import strategy](#import-strategy)
20
22
  - [Layouts](#layouts)
21
23
  - [FileLink component](#filelink-component)
24
+ - [useScroll hook](#useScroll)
22
25
  - [Usage](#usage)
23
26
  - [Generated files](#generated-files)
24
27
  - [API Reference](#api-reference)
@@ -288,9 +291,6 @@ All routes in `src/pages/dashboard/*` will render inside this layout.
288
291
 
289
292
  ---
290
293
 
291
- Top-level pages are always statically imported for faster initial navigation.
292
- All nested pages are lazy-loaded and wrapped in a Suspense boundary.
293
-
294
294
  ## FileLink component
295
295
 
296
296
  The FileLink component is a type safe wrapper for the Link component in react router that uses an autogenerated type to check which routes are available.
@@ -322,7 +322,6 @@ export default function Home() {
322
322
  return (
323
323
  <>
324
324
  Hello Home!
325
- {/* FileRoutes is optional and not required it will work fine with any string if not passed */}
326
325
  <FileLink<FileRoutes> to="test">Test safe</FileLink>
327
326
  {/* or without type safety */}
328
327
  <FileLink to="some-route">Non safe</FileLink>
@@ -331,6 +330,73 @@ export default function Home() {
331
330
  }
332
331
  ```
333
332
 
333
+ ## useScroll
334
+
335
+ Custom React hook that scrolls to the top after navigation.
336
+ Designed to work seamlessly with client-side routing while remaining SSR-safe.
337
+
338
+ ### Features
339
+
340
+ - Automatically scrolls on route change
341
+
342
+ - Supports smooth scrolling
343
+
344
+ - Can scroll either the window or a specific container
345
+
346
+ - Safe to use in SSR environments
347
+
348
+ ### Usage
349
+
350
+ ```tsx
351
+ import { useScroll } from "aaex-file-router";
352
+
353
+ export default function PageWithNavigation() {
354
+ useScroll();
355
+
356
+ return <>{/* rest of content */}</>;
357
+ }
358
+ ```
359
+
360
+ ### Options
361
+
362
+ `useScroll` accepts an optional config object.
363
+
364
+ ```tsx
365
+ useScroll({
366
+ behavior?: ScrollBehavior;
367
+ container?: HTMLElement | null;
368
+ });
369
+ ```
370
+
371
+ | Option | Type | Default | Description |
372
+ | ----------- | --------------------- | ---------- | ---------------------------------------- | ------------------------- |
373
+ | `behavior` | `"auto"` | `"smooth"` | `"auto"` | Scroll animation behavior |
374
+ | `container` | `HTMLElement \| null` | `null` | Scrolls this element instead of `window` |
375
+
376
+ ### Example: smooth scroll
377
+
378
+ ```tsx
379
+ useScroll({
380
+ behavior: "smooth",
381
+ });
382
+ ```
383
+
384
+ ### Example: scroll a container
385
+
386
+ ```tsx
387
+ const ref = useRef<HTMLDivElement>(null);
388
+
389
+ useScroll({
390
+ container: ref.current,
391
+ });
392
+
393
+ return <div ref={ref}>...</div>;
394
+ ```
395
+
396
+ ---
397
+
398
+ <br/>
399
+
334
400
  ## Generated files
335
401
 
336
402
  ### routes.ts
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Scrolls the window or a container to the top on route change
3
+ */
4
+ export declare function useScroll(options?: {
5
+ behavior?: ScrollBehavior;
6
+ container?: HTMLElement | null;
7
+ }): void;
8
+ //# sourceMappingURL=useScroll.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useScroll.d.ts","sourceRoot":"","sources":["../../src/hooks/useScroll.tsx"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE;IAClC,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,SAAS,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;CAChC,QAaA"}
@@ -0,0 +1,19 @@
1
+ import { useEffect } from "react";
2
+ import { useLocation } from "react-router-dom";
3
+ /**
4
+ * Scrolls the window or a container to the top on route change
5
+ */
6
+ export function useScroll(options) {
7
+ const { pathname } = useLocation();
8
+ const behavior = options?.behavior ?? "auto";
9
+ const container = options?.container ?? null;
10
+ useEffect(() => {
11
+ if (container) {
12
+ container.scrollTo({ top: 0, behavior });
13
+ }
14
+ else {
15
+ window.scrollTo({ top: 0, behavior });
16
+ }
17
+ }, [pathname, behavior, container]);
18
+ }
19
+ //# sourceMappingURL=useScroll.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useScroll.js","sourceRoot":"","sources":["../../src/hooks/useScroll.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,OAGzB;IACC,MAAM,EAAE,QAAQ,EAAE,GAAG,WAAW,EAAE,CAAC;IAEnC,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,MAAM,CAAC;IAC7C,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,IAAI,CAAC;IAE7C,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,SAAS,EAAE,CAAC;YACd,SAAS,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC3C,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QACxC,CAAC;IACH,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AACtC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { FileLink } from "./components/FileLink.js";
2
+ export { useScroll } from "./hooks/useScroll.js";
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,0BAA0B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { FileLink } from "./components/FileLink.js";
2
+ export { useScroll } from "./hooks/useScroll.js";
2
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,0BAA0B,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aaex-file-router",
3
- "version": "1.7.5",
3
+ "version": "1.8.0",
4
4
  "description": "A file-based routing system for React projects that automatically generates routes from your file structure. Similar to Next.js App Router or Remix file conventions.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",