@matthesketh/utopia-router 0.1.0 → 0.2.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/dist/index.cjs CHANGED
@@ -101,7 +101,10 @@ function escapeRegex(str) {
101
101
  return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
102
102
  }
103
103
  function matchRoute(url, routes2) {
104
- const pathname = url.pathname;
104
+ let pathname = url.pathname;
105
+ if (pathname.length > 1 && pathname.endsWith("/")) {
106
+ pathname = pathname.slice(0, -1);
107
+ }
105
108
  for (const route of routes2) {
106
109
  const match = route.pattern.exec(pathname);
107
110
  if (match) {
package/dist/index.d.cts CHANGED
@@ -14,11 +14,13 @@ interface Route {
14
14
  /** Parameter names extracted from the path (e.g., ['id'] for '/users/:id'). */
15
15
  params: string[];
16
16
  /** Lazy component import — called only when the route is matched. */
17
- component: () => Promise<any>;
17
+ component: () => Promise<Record<string, unknown>>;
18
18
  /** Optional layout component that wraps the page. */
19
- layout?: () => Promise<any>;
19
+ layout?: () => Promise<Record<string, unknown>>;
20
20
  /** Optional error boundary component shown when loading fails. */
21
- error?: () => Promise<any>;
21
+ error?: () => Promise<Record<string, unknown>>;
22
+ /** Optional metadata (e.g. page title, auth requirements). */
23
+ meta?: Record<string, unknown>;
22
24
  }
23
25
  /**
24
26
  * The result of successfully matching a URL against a route.
@@ -114,7 +116,7 @@ declare function matchRoute(url: URL, routes: Route[]): RouteMatch | null;
114
116
  * @param manifest - Record of file paths to lazy import functions
115
117
  * @returns Ordered array of compiled Route objects
116
118
  */
117
- declare function buildRouteTable(manifest: Record<string, () => Promise<any>>): Route[];
119
+ declare function buildRouteTable(manifest: Record<string, () => Promise<Record<string, unknown>>>): Route[];
118
120
 
119
121
  /** The currently matched route, or null if no route matches. */
120
122
  declare const currentRoute: _matthesketh_utopia_core.Signal<RouteMatch | null>;
package/dist/index.d.ts CHANGED
@@ -14,11 +14,13 @@ interface Route {
14
14
  /** Parameter names extracted from the path (e.g., ['id'] for '/users/:id'). */
15
15
  params: string[];
16
16
  /** Lazy component import — called only when the route is matched. */
17
- component: () => Promise<any>;
17
+ component: () => Promise<Record<string, unknown>>;
18
18
  /** Optional layout component that wraps the page. */
19
- layout?: () => Promise<any>;
19
+ layout?: () => Promise<Record<string, unknown>>;
20
20
  /** Optional error boundary component shown when loading fails. */
21
- error?: () => Promise<any>;
21
+ error?: () => Promise<Record<string, unknown>>;
22
+ /** Optional metadata (e.g. page title, auth requirements). */
23
+ meta?: Record<string, unknown>;
22
24
  }
23
25
  /**
24
26
  * The result of successfully matching a URL against a route.
@@ -114,7 +116,7 @@ declare function matchRoute(url: URL, routes: Route[]): RouteMatch | null;
114
116
  * @param manifest - Record of file paths to lazy import functions
115
117
  * @returns Ordered array of compiled Route objects
116
118
  */
117
- declare function buildRouteTable(manifest: Record<string, () => Promise<any>>): Route[];
119
+ declare function buildRouteTable(manifest: Record<string, () => Promise<Record<string, unknown>>>): Route[];
118
120
 
119
121
  /** The currently matched route, or null if no route matches. */
120
122
  declare const currentRoute: _matthesketh_utopia_core.Signal<RouteMatch | null>;
package/dist/index.js CHANGED
@@ -62,7 +62,10 @@ function escapeRegex(str) {
62
62
  return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
63
63
  }
64
64
  function matchRoute(url, routes2) {
65
- const pathname = url.pathname;
65
+ let pathname = url.pathname;
66
+ if (pathname.length > 1 && pathname.endsWith("/")) {
67
+ pathname = pathname.slice(0, -1);
68
+ }
66
69
  for (const route of routes2) {
67
70
  const match = route.pattern.exec(pathname);
68
71
  if (match) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matthesketh/utopia-router",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "File-based routing for UtopiaJS",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -40,8 +40,8 @@
40
40
  "dist"
41
41
  ],
42
42
  "dependencies": {
43
- "@matthesketh/utopia-runtime": "0.1.0",
44
- "@matthesketh/utopia-core": "0.1.0"
43
+ "@matthesketh/utopia-core": "0.2.0",
44
+ "@matthesketh/utopia-runtime": "0.2.0"
45
45
  },
46
46
  "scripts": {
47
47
  "build": "tsup src/index.ts --format esm,cjs --dts",