Skip to content

Commit bfb059f

Browse files
committedMay 31, 2024
types Route -> RouteDescription
1 parent f77cd0f commit bfb059f

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed
 

‎.changeset/thin-wolves-learn.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/router": patch
3+
---
4+
5+
types Route -> RouteDescription

‎src/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export type {
2929
RouteLoadFunc,
3030
RouteLoadFuncArgs,
3131
RouteDefinition,
32-
Route as RouteInfo,
32+
RouteDescription,
3333
RouteMatch,
3434
RouterIntegration,
3535
RouterUtils,

‎src/routing.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import type {
2525
NavigateOptions,
2626
Navigator,
2727
Params,
28-
Route,
28+
RouteDescription,
2929
RouteContext,
3030
RouteDefinition,
3131
RouteMatch,
@@ -123,7 +123,7 @@ export const useBeforeLeave = (listener: (e: BeforeLeaveEventArgs) => void) => {
123123
onCleanup(s);
124124
};
125125

126-
export function createRoutes(routeDef: RouteDefinition, base: string = ""): Route[] {
126+
export function createRoutes(routeDef: RouteDefinition, base: string = ""): RouteDescription[] {
127127
const { component, load, children, info } = routeDef;
128128
const isLeaf = !children || (Array.isArray(children) && !children.length);
129129

@@ -134,7 +134,7 @@ export function createRoutes(routeDef: RouteDefinition, base: string = ""): Rout
134134
info
135135
};
136136

137-
return asArray(routeDef.path).reduce<Route[]>((acc, originalPath) => {
137+
return asArray(routeDef.path).reduce<RouteDescription[]>((acc, originalPath) => {
138138
for (const expandedPath of expandOptionals(originalPath)) {
139139
const path = joinPaths(base, expandedPath);
140140
let pattern = isLeaf ? path : path.split("/*", 1)[0];
@@ -155,7 +155,7 @@ export function createRoutes(routeDef: RouteDefinition, base: string = ""): Rout
155155
}, []);
156156
}
157157

158-
export function createBranch(routes: Route[], index: number = 0): Branch {
158+
export function createBranch(routes: RouteDescription[], index: number = 0): Branch {
159159
return {
160160
routes,
161161
score: scoreRoute(routes[routes.length - 1]) * 10000 - index,
@@ -184,7 +184,7 @@ function asArray<T>(value: T | T[]): T[] {
184184
export function createBranches(
185185
routeDef: RouteDefinition | RouteDefinition[],
186186
base: string = "",
187-
stack: Route[] = [],
187+
stack: RouteDescription[] = [],
188188
branches: Branch[] = []
189189
): Branch[] {
190190
const routeDefs = asArray(routeDef);

‎src/types.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export interface PathMatch {
113113
}
114114

115115
export interface RouteMatch extends PathMatch {
116-
route: Route;
116+
route: RouteDescription;
117117
}
118118

119119
export interface OutputMatch {
@@ -124,7 +124,7 @@ export interface OutputMatch {
124124
info?: Record<string, any>;
125125
}
126126

127-
export interface Route {
127+
export interface RouteDescription {
128128
key: unknown;
129129
originalPath: string;
130130
pattern: string;
@@ -136,7 +136,7 @@ export interface Route {
136136
}
137137

138138
export interface Branch {
139-
routes: Route[];
139+
routes: RouteDescription[];
140140
score: number;
141141
matcher: (location: string) => RouteMatch[] | null;
142142
}

‎src/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createMemo, getOwner, runWithOwner } from "solid-js";
2-
import type { MatchFilter, MatchFilters, Params, PathMatch, Route, SetParams } from "./types.ts";
2+
import type { MatchFilter, MatchFilters, Params, PathMatch, RouteDescription, SetParams } from "./types.ts";
33

44
const hasSchemeRegex = /^(?:[a-z0-9]+:)?\/\//i;
55
const trimPathRegex = /^\/+|(\/)\/+$/g;
@@ -114,7 +114,7 @@ function matchSegment(input: string, filter?: string | MatchFilter): boolean {
114114
return false;
115115
}
116116

117-
export function scoreRoute(route: Route): number {
117+
export function scoreRoute(route: RouteDescription): number {
118118
const [pattern, splat] = route.pattern.split("/*", 2);
119119
const segments = pattern.split("/").filter(Boolean);
120120
return segments.reduce(

0 commit comments

Comments
 (0)
Please sign in to comment.