File tree Expand file tree Collapse file tree 2 files changed +15
-7
lines changed
packages/solid-router/src Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -28,9 +28,6 @@ export function useActiveLocation(): UseActiveLocationResult {
28
28
return last ( activeLocationMatches )
29
29
} )
30
30
31
-
32
-
33
-
34
31
const getFromPath = ( from ?: string ) => {
35
32
return createMemo ( ( ) => from ?? activeLocationMatch ( ) ?. fullPath ?? currentRouteMatch ( ) . fullPath )
36
33
}
Original file line number Diff line number Diff line change 1
1
import * as Solid from 'solid-js'
2
+ import { last } from '@tanstack/router-core'
2
3
import { useRouter } from './useRouter'
3
- import { useActiveLocation } from './useActiveLocation '
4
+ import { useMatch } from './useMatch '
4
5
import type {
5
6
AnyRouter ,
6
7
FromPathOption ,
@@ -17,13 +18,23 @@ export function useNavigate<
17
18
} ) : UseNavigateResult < TDefaultFrom > {
18
19
const router = useRouter ( )
19
20
20
- const { getFromPath} = useActiveLocation ( )
21
+ const matchIndex = useMatch ( {
22
+ strict : false ,
23
+ select : ( match ) => match . index ,
24
+ } )
25
+
21
26
return ( ( options : NavigateOptions ) => {
22
- const from = getFromPath ( options . from ?? _defaultOpts ?. from )
27
+ const currentRouteMatches = router . matchRoutes ( router . latestLocation , {
28
+ _buildLocation : false ,
29
+ } )
23
30
24
31
return router . navigate ( {
25
32
...options ,
26
- from : from ( )
33
+ from :
34
+ options . from ??
35
+ _defaultOpts ?. from ??
36
+ last ( currentRouteMatches ) ?. fullPath ??
37
+ router . state . matches [ matchIndex ( ) ] ! . fullPath ,
27
38
} )
28
39
} ) as UseNavigateResult < TDefaultFrom >
29
40
}
You can’t perform that action at this time.
0 commit comments