Skip to content

Commit 7432d65

Browse files
committed
refactor: simplify resolution
1 parent 7a250b3 commit 7432d65

File tree

1 file changed

+4
-40
lines changed

1 file changed

+4
-40
lines changed

packages/router/src/experimental/router.ts

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import type {
5252
RouteLocationResolved,
5353
RouteMap,
5454
RouteRecordNameGeneric,
55+
RouteRecordRedirectOption,
5556
} from '../typed-routes'
5657
import {
5758
Lazy,
@@ -180,7 +181,6 @@ export interface EXPERIMENTAL_RouterOptions_Base extends PathParserOptions {
180181
// linkInactiveClass?: string
181182
}
182183

183-
// TODO: non matchable and parent
184184
/**
185185
* Internal type for common properties among all kind of {@link RouteRecordRaw}.
186186
*/
@@ -192,7 +192,7 @@ export interface EXPERIMENTAL_RouteRecord_Base
192192
* before any navigation guard and triggers a new navigation with the new
193193
* target location.
194194
*/
195-
// redirect?: RouteRecordRedirectOption;
195+
redirect?: RouteRecordRedirectOption
196196

197197
// TODO:
198198
/**
@@ -217,12 +217,6 @@ export interface EXPERIMENTAL_RouteRecord_Base
217217
*/
218218
meta?: RouteMeta
219219

220-
// TODO:
221-
/**
222-
* Array of nested routes.
223-
*/
224-
// children?: RouteRecordRaw[]
225-
226220
/**
227221
* Components to display when the URL matches this route. Allow using named views.
228222
*/
@@ -247,8 +241,6 @@ export interface EXPERIMENTAL_RouteRecord_Matchable
247241
components: Record<string, RawRouteComponent>
248242

249243
parent?: EXPERIMENTAL_RouteRecordNormalized | null
250-
251-
redirect?: never
252244
}
253245

254246
export interface EXPERIMENTAL_RouteRecord_Group
@@ -261,9 +253,6 @@ export interface EXPERIMENTAL_RouteRecord_Group
261253
components?: Record<string, RawRouteComponent>
262254

263255
parent?: EXPERIMENTAL_RouteRecordNormalized | null
264-
265-
// TODO:
266-
// redirect?: something
267256
}
268257

269258
export type EXPERIMENTAL_RouteRecordRaw =
@@ -318,9 +307,6 @@ export interface EXPERIMENTAL_RouteRecordNormalized_Matchable
318307

319308
parent: EXPERIMENTAL_RouteRecordNormalized | null
320309

321-
// TODO:
322-
// redirect?: unknown
323-
324310
components: Record<string, RawRouteComponent>
325311
}
326312

@@ -383,6 +369,7 @@ export function mergeRouteRecord(
383369
) {
384370
for (const record of routeRecords) {
385371
main.meta = { ...main.meta, ...record.meta }
372+
main.props = { ...main.props, ...record.props }
386373
}
387374
return main
388375
}
@@ -624,8 +611,6 @@ export function experimental_createRouter(
624611
return !!resolver.getRecord(name)
625612
}
626613

627-
// TODO: replace usage with resolver.resolve()
628-
629614
// NOTE: to support multiple overloads
630615
type TRecord = EXPERIMENTAL_RouteRecordNormalized
631616
type _resolveArgs =
@@ -662,27 +647,6 @@ export function experimental_createRouter(
662647
function resolve(
663648
...[to, currentLocation]: _resolveArgs
664649
): RouteLocationResolved {
665-
// const resolve: Router['resolve'] = (rawLocation: RouteLocationRaw, currentLocation) => {
666-
// const objectLocation = routerLocationAsObject(rawLocation)
667-
// we create a copy to modify it later
668-
// TODO: in the experimental version, allow configuring this
669-
currentLocation =
670-
// TODO: || currentRoute.value never evaluated
671-
currentLocation && assign({}, currentLocation || currentRoute.value)
672-
// currentLocation = assign({}, currentLocation || currentRoute.value)
673-
674-
// FIXME: should this be achieved by matchers?
675-
// remove any nullish param
676-
// if ('params' in rawLocation) {
677-
// const targetParams = assign({}, rawLocation.params)
678-
// for (const key in targetParams) {
679-
// if (targetParams[key] == null) {
680-
// delete targetParams[key]
681-
// }
682-
// }
683-
// rawLocation.params = targetParams
684-
// }
685-
686650
const matchedRoute = resolver.resolve(
687651
// @ts-expect-error FIXME: incompatible types
688652
to,
@@ -739,7 +703,7 @@ export function experimental_createRouter(
739703
): RouteLocationRaw | void {
740704
const redirect = to.matched.at(-1)?.redirect
741705
if (redirect) {
742-
return resolve(
706+
return resolver.resolve(
743707
// @ts-expect-error: TODO: allow redirect to return the first argument of resolve or a tuple consisting of the arguments?
744708
typeof redirect === 'function' ? redirect(to, from) : redirect,
745709
from

0 commit comments

Comments
 (0)