File tree Expand file tree Collapse file tree 4 files changed +1555
-134
lines changed Expand file tree Collapse file tree 4 files changed +1555
-134
lines changed Original file line number Diff line number Diff line change @@ -135,15 +135,30 @@ export function useLinkProps<
135
135
136
136
// when `from` is not supplied, use the route of the current match as the `from` location
137
137
// so relative routing works as expected
138
- const from = useMatch ( {
138
+ // const from = useMatch({
139
+ // strict: false,
140
+ // select: (match) => options.from ?? match.fullPath,
141
+ // })
142
+
143
+ const matchIndex = useMatch ( {
139
144
strict : false ,
140
- select : ( match ) => options . from ?? match . fullPath ,
145
+ select : ( match ) => match . index ,
141
146
} )
142
147
143
- const _options = ( ) => ( {
144
- ...options ,
145
- from : from ( ) ,
146
- } )
148
+ const _options = ( ) => {
149
+ const currentRouteMatches = router . matchRoutes ( router . latestLocation , {
150
+ _buildLocation : false ,
151
+ } )
152
+
153
+ const from = options . from ??
154
+ currentRouteMatches . slice ( - 1 ) [ 0 ] ?. fullPath ??
155
+ router . state . matches [ matchIndex ( ) ] ! . fullPath
156
+
157
+ return ( {
158
+ ...options ,
159
+ from
160
+ } )
161
+ }
147
162
148
163
const next = Solid . createMemo ( ( ) => {
149
164
currentSearch ( )
Original file line number Diff line number Diff line change @@ -15,20 +15,25 @@ export function useNavigate<
15
15
> ( _defaultOpts ?: {
16
16
from ?: FromPathOption < TRouter , TDefaultFrom >
17
17
} ) : UseNavigateResult < TDefaultFrom > {
18
- const { navigate , state } = useRouter ( )
18
+ const router = useRouter ( )
19
19
20
20
const matchIndex = useMatch ( {
21
21
strict : false ,
22
22
select : ( match ) => match . index ,
23
23
} )
24
24
25
25
return ( ( options : NavigateOptions ) => {
26
- return navigate ( {
26
+ const currentRouteMatches = router . matchRoutes ( router . latestLocation , {
27
+ _buildLocation : false ,
28
+ } )
29
+
30
+ return router . navigate ( {
27
31
...options ,
28
32
from :
29
33
options . from ??
30
34
_defaultOpts ?. from ??
31
- state . matches [ matchIndex ( ) ] ! . fullPath ,
35
+ currentRouteMatches . slice ( - 1 ) [ 0 ] ?. fullPath ??
36
+ router . state . matches [ matchIndex ( ) ] ! . fullPath
32
37
} )
33
38
} ) as UseNavigateResult < TDefaultFrom >
34
39
}
You can’t perform that action at this time.
0 commit comments