Skip to content

Commit 8ee366e

Browse files
committed
fix #122 expose params to full route
1 parent 1bf46d1 commit 8ee366e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/components.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ import type {
2323
LocationChangeSignal,
2424
MatchFilters,
2525
Navigator,
26+
Params,
2627
RouteContext,
2728
RouteDataFunc,
2829
RouteDefinition,
2930
RouterIntegration
3031
} from "./types";
31-
import { joinPaths, normalizePath } from "./utils";
32+
import { joinPaths, normalizePath, createMemoObject } from "./utils";
3233

3334
declare module "solid-js" {
3435
namespace JSX {
@@ -84,6 +85,14 @@ export const Routes = (props: RoutesProps) => {
8485
createBranches(routeDefs(), joinPaths(parentRoute.pattern, props.base || ""), Outlet)
8586
);
8687
const matches = createMemo(() => getRouteMatches(branches(), router.location.pathname));
88+
const params = createMemoObject(() => {
89+
const m = matches();
90+
const params: Params = {};
91+
for (let i = 0; i < m.length; i++) {
92+
Object.assign(params, m[i].params);
93+
}
94+
return params;
95+
});
8796

8897
if (router.out) {
8998
router.out.matches.push(
@@ -121,7 +130,8 @@ export const Routes = (props: RoutesProps) => {
121130
router,
122131
next[i - 1] || parentRoute,
123132
() => routeStates()[i + 1],
124-
() => matches()[i]
133+
() => matches()[i],
134+
params
125135
);
126136
});
127137
}

src/routing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,12 +507,12 @@ export function createRouteContext(
507507
router: RouterContext,
508508
parent: RouteContext,
509509
child: () => RouteContext,
510-
match: () => RouteMatch
510+
match: () => RouteMatch,
511+
params: Params
511512
): RouteContext {
512513
const { base, location, navigatorFactory } = router;
513514
const { pattern, element: outlet, preload, data } = match().route;
514515
const path = createMemo(() => match().path);
515-
const params = createMemoObject(() => match().params);
516516

517517
preload && preload();
518518

0 commit comments

Comments
 (0)