aaex-file-router 1.7.4 → 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 +72 -6
- package/dist/components/FileLink.d.ts +4 -3
- package/dist/components/FileLink.d.ts.map +1 -1
- package/dist/components/FileLink.js +6 -5
- package/dist/components/FileLink.js.map +1 -1
- package/dist/hooks/useScroll.d.ts +8 -0
- package/dist/hooks/useScroll.d.ts.map +1 -0
- package/dist/hooks/useScroll.js +19 -0
- package/dist/hooks/useScroll.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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.
|
|
6
|
-
|
|
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
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
interface FileLinkProps<RouteType extends string = string> {
|
|
2
|
+
interface FileLinkProps<RouteType extends string = string> extends React.PropsWithChildren {
|
|
3
3
|
to: RouteType;
|
|
4
|
-
|
|
4
|
+
activeClassName?: string;
|
|
5
|
+
className?: string;
|
|
5
6
|
}
|
|
6
|
-
export declare function FileLink<RouteType extends string = string>({ to, children, }: FileLinkProps<RouteType>): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare function FileLink<RouteType extends string = string>({ to, children, activeClassName, className, }: FileLinkProps<RouteType>): import("react/jsx-runtime").JSX.Element;
|
|
7
8
|
export {};
|
|
8
9
|
//# sourceMappingURL=FileLink.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileLink.d.ts","sourceRoot":"","sources":["../../src/components/FileLink.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,UAAU,aAAa,CAAC,SAAS,SAAS,MAAM,GAAG,MAAM;
|
|
1
|
+
{"version":3,"file":"FileLink.d.ts","sourceRoot":"","sources":["../../src/components/FileLink.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,UAAU,aAAa,CAAC,SAAS,SAAS,MAAM,GAAG,MAAM,CACvD,SAAQ,KAAK,CAAC,iBAAiB;IAC/B,EAAE,EAAE,SAAS,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,QAAQ,CAAC,SAAS,SAAS,MAAM,GAAG,MAAM,EAAE,EAC1D,EAAE,EACF,QAAQ,EACR,eAA0B,EAC1B,SAAc,GACf,EAAE,aAAa,CAAC,SAAS,CAAC,2CAmB1B"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Link } from "react-router-dom";
|
|
3
|
-
export function FileLink({ to, children, }) {
|
|
2
|
+
import { Link, useLocation } from "react-router-dom";
|
|
3
|
+
export function FileLink({ to, children, activeClassName = "active", className = "", }) {
|
|
4
4
|
const isServer = typeof window === "undefined";
|
|
5
5
|
if (isServer) {
|
|
6
|
-
//
|
|
6
|
+
// SSR fallback
|
|
7
7
|
return _jsx("a", { href: to, children: children });
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const location = useLocation();
|
|
10
|
+
const isActive = location.pathname === to;
|
|
11
|
+
return (_jsx(Link, { to: to, className: `${className} ${isActive ? activeClassName : ""}`.trim(), children: children }));
|
|
11
12
|
}
|
|
12
13
|
//# sourceMappingURL=FileLink.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileLink.js","sourceRoot":"","sources":["../../src/components/FileLink.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"FileLink.js","sourceRoot":"","sources":["../../src/components/FileLink.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AASrD,MAAM,UAAU,QAAQ,CAAoC,EAC1D,EAAE,EACF,QAAQ,EACR,eAAe,GAAG,QAAQ,EAC1B,SAAS,GAAG,EAAE,GACW;IACzB,MAAM,QAAQ,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;IAE/C,IAAI,QAAQ,EAAE,CAAC;QACb,eAAe;QACf,OAAO,YAAG,IAAI,EAAE,EAAY,YAAG,QAAQ,GAAK,CAAC;IAC/C,CAAC;IAED,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,KAAK,EAAE,CAAC;IAE1C,OAAO,CACL,KAAC,IAAI,IACH,EAAE,EAAE,EAAY,EAChB,SAAS,EAAE,GAAG,SAAS,IAAI,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,YAElE,QAAQ,GACJ,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -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
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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.
|
|
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",
|