Skip to content

Commit 745107c

Browse files
committed
replicate changes to Solid
1 parent ba524f1 commit 745107c

File tree

4 files changed

+1555
-134
lines changed

4 files changed

+1555
-134
lines changed

packages/solid-router/src/link.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,30 @@ export function useLinkProps<
135135

136136
// when `from` is not supplied, use the route of the current match as the `from` location
137137
// 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({
139144
strict: false,
140-
select: (match) => options.from ?? match.fullPath,
145+
select: (match) => match.index,
141146
})
142147

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+
}
147162

148163
const next = Solid.createMemo(() => {
149164
currentSearch()

packages/solid-router/src/useNavigate.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,25 @@ export function useNavigate<
1515
>(_defaultOpts?: {
1616
from?: FromPathOption<TRouter, TDefaultFrom>
1717
}): UseNavigateResult<TDefaultFrom> {
18-
const { navigate, state } = useRouter()
18+
const router = useRouter()
1919

2020
const matchIndex = useMatch({
2121
strict: false,
2222
select: (match) => match.index,
2323
})
2424

2525
return ((options: NavigateOptions) => {
26-
return navigate({
26+
const currentRouteMatches= router.matchRoutes(router.latestLocation, {
27+
_buildLocation: false,
28+
})
29+
30+
return router.navigate({
2731
...options,
2832
from:
2933
options.from ??
3034
_defaultOpts?.from ??
31-
state.matches[matchIndex()]!.fullPath,
35+
currentRouteMatches.slice(-1)[0]?.fullPath ??
36+
router.state.matches[matchIndex()]!.fullPath
3237
})
3338
}) as UseNavigateResult<TDefaultFrom>
3439
}

0 commit comments

Comments
 (0)