1
1
import { last } from '@tanstack/router-core'
2
- import { createEffect , createMemo , createSignal } from 'solid-js'
2
+ import { createEffect , createMemo , createSignal } from 'solid-js'
3
3
import { useMatch } from './useMatch'
4
4
import { useRouter } from './useRouter'
5
5
import { useRouterState } from './useRouterState'
6
- import type { Accessor } from 'solid-js' ;
6
+ import type { Accessor } from 'solid-js'
7
7
import type { ParsedLocation } from '@tanstack/router-core'
8
8
9
9
export type UseLocationResult = {
@@ -12,14 +12,22 @@ export type UseLocationResult = {
12
12
setActiveLocation : ( location ?: ParsedLocation ) => void
13
13
}
14
14
15
- export function useActiveLocation ( location ?: ParsedLocation ) : UseLocationResult {
15
+ export function useActiveLocation (
16
+ location ?: ParsedLocation ,
17
+ ) : UseLocationResult {
16
18
const router = useRouter ( )
17
19
// we are not using a variable here for router state location since we need to only calculate that if the location is not passed in. It can result in unnecessary history actions if we do that.
18
- const [ activeLocation , setActiveLocation ] = createSignal < ParsedLocation > ( location ?? useRouterState ( { select : s => s . location } ) ( ) )
19
- const [ customActiveLocation , setCustomActiveLocation ] = createSignal < ParsedLocation | undefined > ( location )
20
+ const [ activeLocation , setActiveLocation ] = createSignal < ParsedLocation > (
21
+ location ?? useRouterState ( { select : ( s ) => s . location } ) ( ) ,
22
+ )
23
+ const [ customActiveLocation , setCustomActiveLocation ] = createSignal <
24
+ ParsedLocation | undefined
25
+ > ( location )
20
26
21
27
createEffect ( ( ) => {
22
- setActiveLocation ( customActiveLocation ( ) ?? useRouterState ( { select : s => s . location } ) ( ) )
28
+ setActiveLocation (
29
+ customActiveLocation ( ) ?? useRouterState ( { select : ( s ) => s . location } ) ( ) ,
30
+ )
23
31
} )
24
32
25
33
const currentRouteMatch = useMatch ( {
@@ -29,9 +37,12 @@ export function useActiveLocation(location?: ParsedLocation): UseLocationResult
29
37
30
38
const getFromPath = ( from ?: string ) =>
31
39
createMemo ( ( ) => {
32
- const currentRouteMatches = router . matchRoutes ( customActiveLocation ( ) ?? activeLocation ( ) , {
33
- _buildLocation : false ,
34
- } )
40
+ const currentRouteMatches = router . matchRoutes (
41
+ customActiveLocation ( ) ?? activeLocation ( ) ,
42
+ {
43
+ _buildLocation : false ,
44
+ } ,
45
+ )
35
46
36
47
return (
37
48
from ??
0 commit comments