1- /// <reference types="@stackflow/plugin-history-sync" />
2-
31import type {
42 InferActivityParams ,
53 RegisteredActivityName ,
64} from "@stackflow/config" ;
7- import type { Route } from "@stackflow/plugin-history-sync" ;
8- import { useConfig , useFlow } from "@stackflow/react" ;
5+ import { useFlow } from "@stackflow/react" ;
96import { useMemo } from "react" ;
7+ import { useLinkUrlResolver } from "./LinkUrlResolverContext" ;
108import { omit } from "./omit" ;
119
12- function toRoute < T > ( route : string | Route < T > ) : Route < T > {
13- return typeof route === "string" ? { path : route , decode : undefined } : route ;
14- }
15-
1610type AnchorProps = Omit <
1711 React . DetailedHTMLProps <
1812 React . AnchorHTMLAttributes < HTMLAnchorElement > ,
@@ -31,26 +25,13 @@ export interface LinkProps<K extends RegisteredActivityName>
3125}
3226
3327export function Link < K extends RegisteredActivityName > ( props : LinkProps < K > ) {
34- const config = useConfig ( ) ;
28+ const urlResolver = useLinkUrlResolver ( ) ;
3529 const { push, replace } = useFlow ( ) ;
3630
37- const href = useMemo ( ( ) => {
38- const match = config . activities . find ( ( r ) => r . name === props . activityName ) ;
39-
40- if ( ! match || ! match . route || ! config . historySync ) {
41- return undefined ;
42- }
43-
44- const { path, decode } = Array . isArray ( match . route )
45- ? toRoute ( match . route [ 0 ] )
46- : toRoute ( match . route ) ;
47-
48- const { makeTemplate, urlPatternOptions } = config . historySync ;
49-
50- const template = makeTemplate ( { path, decode } , urlPatternOptions ) ;
51-
52- return template . fill ( props . activityParams ) ;
53- } , [ config , props . activityName , props . activityParams ] ) ;
31+ const href = useMemo (
32+ ( ) => urlResolver . makeActivityUrl ( props . activityName , props . activityParams ) ,
33+ [ urlResolver . makeActivityUrl , props . activityName , props . activityParams ] ,
34+ ) ;
5435
5536 const anchorProps = omit ( props , [
5637 // Custom Props
0 commit comments