@@ -32,7 +32,6 @@ import type {
3232 RouteSectionProps ,
3333 Location
3434} from "../types.js" ;
35- import { createMemoObject } from "../utils.js" ;
3635
3736export type BaseRouterProps = {
3837 base ?: string ;
@@ -53,16 +52,14 @@ export const createRouterComponent = (router: RouterIntegration) => (props: Base
5352
5453 const branches = createMemo ( ( ) => createBranches ( routeDefs ( ) , props . base || "" ) ) ;
5554 let context : Owner ;
56- const routerState = createRouterContext ( router , ( ) => context , branches , {
55+ const routerState = createRouterContext ( router , branches , ( ) => context , {
5756 base,
5857 singleFlight : props . singleFlight
5958 } ) ;
60- const location = routerState . location ;
6159 router . create && router . create ( routerState ) ;
62-
6360 return (
6461 < RouterContextObj . Provider value = { routerState } >
65- < Root location = { location } root = { props . root } load = { props . rootLoad } >
62+ < Root routerState = { routerState } root = { props . root } load = { props . rootLoad } >
6663 { ( context = getOwner ( ) ! ) && null }
6764 < Routes routerState = { routerState } branches = { branches ( ) } />
6865 </ Root >
@@ -71,19 +68,20 @@ export const createRouterComponent = (router: RouterIntegration) => (props: Base
7168} ;
7269
7370function Root ( props : {
74- location : Location < unknown > ;
71+ routerState : RouterContext ;
7572 root ?: Component < RouteSectionProps > ;
7673 load ?: RouteLoadFunc ;
7774 children : JSX . Element ;
7875} ) {
79- const location = props . location ;
76+ const location = props . routerState . location ;
77+ const params = props . routerState . params ;
8078 const data = createMemo (
81- ( ) => props . load && untrack ( ( ) => props . load ! ( { params : { } , location, intent : "preload" } ) )
79+ ( ) => props . load && untrack ( ( ) => props . load ! ( { params, location, intent : "preload" } ) )
8280 ) ;
8381 return (
8482 < Show when = { props . root } keyed fallback = { props . children } >
8583 { Root => (
86- < Root params = { { } } location = { location } data = { data ( ) } >
84+ < Root params = { params } location = { location } data = { data ( ) } >
8785 { props . children }
8886 </ Root >
8987 ) }
@@ -92,10 +90,6 @@ function Root(props: {
9290}
9391
9492function Routes ( props : { routerState : RouterContext ; branches : Branch [ ] } ) {
95- const matches = createMemo ( ( ) =>
96- getRouteMatches ( props . branches , props . routerState . location . pathname )
97- ) ;
98-
9993 if ( isServer ) {
10094 const e = getRequestEvent ( ) ;
10195 if ( e && e . router && e . router . dataOnly ) {
@@ -104,27 +98,20 @@ function Routes(props: { routerState: RouterContext; branches: Branch[] }) {
10498 }
10599 e &&
106100 ( ( e . router || ( e . router = { } ) ) . matches ||
107- ( e . router . matches = matches ( ) . map ( ( { route, path, params } ) => ( {
101+ ( e . router . matches = props . routerState . matches ( ) . map ( ( { route, path, params } ) => ( {
108102 path : route . originalPath ,
109103 pattern : route . pattern ,
110104 match : path ,
111105 params,
112106 info : route . info
113107 } ) ) ) ) ;
114108 }
115- const params = createMemoObject ( ( ) => {
116- const m = matches ( ) ;
117- const params : Params = { } ;
118- for ( let i = 0 ; i < m . length ; i ++ ) {
119- Object . assign ( params , m [ i ] . params ) ;
120- }
121- return params ;
122- } ) ;
109+
123110 const disposers : ( ( ) => void ) [ ] = [ ] ;
124111 let root : RouteContext | undefined ;
125112
126113 const routeStates = createMemo (
127- on ( matches , ( nextMatches , prevMatches , prev : RouteContext [ ] | undefined ) => {
114+ on ( props . routerState . matches , ( nextMatches , prevMatches , prev : RouteContext [ ] | undefined ) => {
128115 let equal = prevMatches && nextMatches . length === prevMatches . length ;
129116 const next : RouteContext [ ] = [ ] ;
130117 for ( let i = 0 , len = nextMatches . length ; i < len ; i ++ ) {
@@ -145,8 +132,7 @@ function Routes(props: { routerState: RouterContext; branches: Branch[] }) {
145132 props . routerState ,
146133 next [ i - 1 ] || props . routerState . base ,
147134 createOutlet ( ( ) => routeStates ( ) [ i + 1 ] ) ,
148- ( ) => matches ( ) [ i ] ,
149- params
135+ ( ) => props . routerState . matches ( ) [ i ]
150136 ) ;
151137 } ) ;
152138 }
0 commit comments