Skip to content

Commit 8feb3c0

Browse files
committed
revert change to SolidJS useNavigate
1 parent d3391ea commit 8feb3c0

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

packages/solid-router/src/useActiveLocation.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ export function useActiveLocation(): UseActiveLocationResult {
2828
return last(activeLocationMatches)
2929
})
3030

31-
32-
33-
3431
const getFromPath = (from?: string) => {
3532
return createMemo(() => from ?? activeLocationMatch()?.fullPath ?? currentRouteMatch().fullPath)
3633
}

packages/solid-router/src/useNavigate.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as Solid from 'solid-js'
2+
import { last } from '@tanstack/router-core'
23
import { useRouter } from './useRouter'
3-
import { useActiveLocation } from './useActiveLocation'
4+
import { useMatch } from './useMatch'
45
import type {
56
AnyRouter,
67
FromPathOption,
@@ -17,13 +18,23 @@ export function useNavigate<
1718
}): UseNavigateResult<TDefaultFrom> {
1819
const router = useRouter()
1920

20-
const {getFromPath} = useActiveLocation()
21+
const matchIndex = useMatch({
22+
strict: false,
23+
select: (match) => match.index,
24+
})
25+
2126
return ((options: NavigateOptions) => {
22-
const from = getFromPath(options.from ?? _defaultOpts?.from)
27+
const currentRouteMatches = router.matchRoutes(router.latestLocation, {
28+
_buildLocation: false,
29+
})
2330

2431
return router.navigate({
2532
...options,
26-
from: from()
33+
from:
34+
options.from ??
35+
_defaultOpts?.from ??
36+
last(currentRouteMatches)?.fullPath ??
37+
router.state.matches[matchIndex()]!.fullPath,
2738
})
2839
}) as UseNavigateResult<TDefaultFrom>
2940
}

0 commit comments

Comments
 (0)