@@ -4,7 +4,7 @@ import type { RouterContext } from "../types.js";
44import { actions } from "./action.js" ;
55import { mockBase } from "../utils.js" ;
66
7- export function setupNativeEvents ( preload = true , explicitLinks = false , actionBase = "/_server" ) {
7+ export function setupNativeEvents ( preload = true , explicitLinks = false , actionBase = "/_server" , transformUrl ?: ( url : string ) => string ) {
88 return ( router : RouterContext ) => {
99 const basePath = router . base . path ( ) ;
1010 const navigateFromRoute = router . navigatorFactory ( router . base ) ;
@@ -71,6 +71,9 @@ export function setupNativeEvents(preload = true, explicitLinks = false, actionB
7171 const res = handleAnchor ( evt as MouseEvent ) ;
7272 if ( ! res ) return ;
7373 const [ a , url ] = res ;
74+ if ( typeof transformUrl === "function" ) {
75+ url . pathname = transformUrl ( url . pathname ) ;
76+ }
7477 if ( ! preloadTimeout [ url . pathname ] )
7578 router . preloadRoute ( url , a . getAttribute ( "preload" ) !== "false" ) ;
7679 }
@@ -79,6 +82,9 @@ export function setupNativeEvents(preload = true, explicitLinks = false, actionB
7982 const res = handleAnchor ( evt as MouseEvent ) ;
8083 if ( ! res ) return ;
8184 const [ a , url ] = res ;
85+ if ( typeof transformUrl === "function" ) {
86+ url . pathname = transformUrl ( url . pathname ) ;
87+ }
8288 if ( preloadTimeout [ url . pathname ] ) return ;
8389 preloadTimeout [ url . pathname ] = setTimeout ( ( ) => {
8490 router . preloadRoute ( url , a . getAttribute ( "preload" ) !== "false" ) ;
@@ -90,6 +96,9 @@ export function setupNativeEvents(preload = true, explicitLinks = false, actionB
9096 const res = handleAnchor ( evt as MouseEvent ) ;
9197 if ( ! res ) return ;
9298 const [ , url ] = res ;
99+ if ( typeof transformUrl === "function" ) {
100+ url . pathname = transformUrl ( url . pathname ) ;
101+ }
93102 if ( preloadTimeout [ url . pathname ] ) {
94103 clearTimeout ( preloadTimeout [ url . pathname ] ) ;
95104 delete preloadTimeout [ url . pathname ] ;
0 commit comments