11import type { CommonRouteNavigation , ResolvedRoute , RouteName , RouteNavigation } from '~/models/route.model.js' ;
2- import type { ResolvedRouterLocationSnapshot , RouterNavigationOptions } from '~/models/router.model.js' ;
2+ import type { IRouter , ResolvedRouterLocationSnapshot , RouterNavigationOptions } from '~/models/router.model.js' ;
33
44import { resolveComponent } from '@dvcol/svelte-utils/component' ;
55
@@ -79,7 +79,7 @@ export type LinkNavigateFunction = <Action extends 'replace' | 'push' | 'resolve
7979 * @throws {MissingRouterContextError } - If the router context is not found
8080 */
8181export function getLinkNavigateFunction ( options : LinkNavigateOptions = { } ) : LinkNavigateFunction {
82- const router = getRouter ( ) ;
82+ const router = options ?. router || getRouter ( ) ;
8383 if ( ! router ) throw new MissingRouterContextError ( ) ;
8484
8585 return async ( event , node , action ) => {
@@ -155,8 +155,13 @@ export function normalizeLinkAttributes(node: HTMLElement, options: LinkNavigate
155155 return { node, options } ;
156156}
157157
158- export interface LinkNavigateOptions < Name extends RouteName = RouteName > extends CommonRouteNavigation ,
158+ export interface LinkNavigateOptions < Name extends RouteName = RouteName , Path extends string = string > extends CommonRouteNavigation < Path > ,
159159 RouterNavigationOptions {
160+ /**
161+ * Optional router instance to use for matching.
162+ * If not provided, the router will be extracted from the context.
163+ */
164+ router ?: IRouter < Name > ;
160165 /**
161166 * Whether to resolve the link on hover or focus.
162167 * If a string is provided, it will be used as the name of the view to resolve instead of the link's target.
@@ -173,7 +178,7 @@ export interface LinkNavigateOptions<Name extends RouteName = RouteName> extends
173178 /**
174179 * The path of the route to navigate to.
175180 */
176- path ?: string ;
181+ path ?: Path ;
177182 /**
178183 * Whether the link is disabled.
179184 */
0 commit comments