@@ -6,8 +6,8 @@ import { isString, StateDeclaration, TransitionOptions } from '@uirouter/core';
6
6
import { UISrefActiveContext } from '../components' ;
7
7
import { UIRouterReact } from '../core' ;
8
8
import { useDeepObjectDiff } from './useDeepObjectDiff' ;
9
+ import { useParentView } from './useParentView' ;
9
10
import { useRouter } from './useRouter' ;
10
- import { useViewContextState } from './useViewContextState' ;
11
11
12
12
export interface LinkProps {
13
13
onClick : React . MouseEventHandler < any > ;
@@ -26,12 +26,12 @@ function useListOfAllStates(router: UIRouterReact) {
26
26
}
27
27
28
28
/** @hidden Gets the StateDeclaration that this sref targets */
29
- function useTargetState ( router : UIRouterReact , stateName : string , context : StateDeclaration ) : StateDeclaration {
29
+ function useTargetState ( router : UIRouterReact , stateName : string , relative : string ) : StateDeclaration {
30
30
// Whenever any states are added/removed from the registry, get the target state again
31
31
const allStates = useListOfAllStates ( router ) ;
32
32
return useMemo ( ( ) => {
33
- return router . stateRegistry . get ( stateName , context ) ;
34
- } , [ router , stateName , context , allStates ] ) ;
33
+ return router . stateRegistry . get ( stateName , relative ) ;
34
+ } , [ router , stateName , relative , allStates ] ) ;
35
35
}
36
36
37
37
/**
@@ -74,9 +74,9 @@ export function useSref(stateName: string, params: object = {}, options: Transit
74
74
// memoize the params object until the nested values actually change so they can be used as deps
75
75
const paramsMemo = useMemo ( ( ) => params , [ useDeepObjectDiff ( params ) ] ) ;
76
76
77
- const contextState : StateDeclaration = useViewContextState ( router ) ;
78
- const optionsMemo = useMemo ( ( ) => ( { relative : contextState , inherit : true , ...options } ) , [ contextState , options ] ) ;
79
- const targetState = useTargetState ( router , stateName , contextState ) ;
77
+ const relative : string = useParentView ( ) . context . name ;
78
+ const optionsMemo = useMemo ( ( ) => ( { relative, inherit : true , ...options } ) , [ relative , options ] ) ;
79
+ const targetState = useTargetState ( router , stateName , relative ) ;
80
80
// Update href when the target StateDeclaration changes (in case the the state definition itself changes)
81
81
// This is necessary to handle things like future states
82
82
const href = useMemo ( ( ) => {
0 commit comments