1- import { h , Fragment , createContext , cloneElement , toChildArray } from 'preact' ;
1+ import { h , createContext , cloneElement , toChildArray } from 'preact' ;
22import { useContext , useMemo , useReducer , useLayoutEffect , useRef } from 'preact/hooks' ;
33
44/**
@@ -138,6 +138,7 @@ export function Router(props) {
138138 if ( ! url ) {
139139 throw new Error ( `preact-iso's <Router> must be used within a <LocationProvider>, see: https://github.com/preactjs/preact-iso#locationprovider` ) ;
140140 }
141+ const { rest = path } = useContext ( RouterContext ) ;
141142
142143 const isLoading = useRef ( false ) ;
143144 const prevRoute = useRef ( path ) ;
@@ -158,11 +159,11 @@ export function Router(props) {
158159 let pathRoute , defaultRoute , matchProps ;
159160 toChildArray ( props . children ) . some ( ( /** @type {VNode<any> } */ vnode ) => {
160161 const matches = exec (
161- path ,
162+ rest ,
162163 vnode . props . path ,
163164 ( matchProps = {
164165 ...vnode . props ,
165- path,
166+ path : rest ,
166167 pathParams : Object . assign ( { } , pathParams ) ,
167168 searchParams,
168169 } ) ) ;
@@ -178,7 +179,7 @@ export function Router(props) {
178179 const routeChanged = useMemo ( ( ) => {
179180 prev . current = cur . current ;
180181
181- cur . current = /** @type {VNode<any> } */ ( h ( Fragment , { key : path } , incoming ) ) ;
182+ cur . current = /** @type {VNode<any> } */ ( h ( RouterContext . Provider , { value : matchProps } , incoming ) ) ;
182183
183184 // Only mark as an update if the route component changed.
184185 const outgoing = prev . current && prev . current . props . children ;
@@ -292,6 +293,9 @@ Router.Provider = LocationProvider;
292293LocationProvider . ctx = createContext (
293294 /** @type {import('./router.d.ts').LocationHook & { wasPush: boolean } } */ ( { } )
294295) ;
296+ const RouterContext = createContext (
297+ /** @type {{ rest: string } } */ ( { } )
298+ ) ;
295299
296300export const Route = props => h ( props . component , props ) ;
297301
0 commit comments