@@ -76,13 +76,10 @@ export const goto = {
76
76
return derived ( url , $url =>
77
77
/** @type {Goto } */
78
78
( pathOrNode , userParams , options ) => {
79
- const path =
80
- typeof pathOrNode === 'string' ? pathOrNode : pathOrNode ?. path
81
-
82
79
/** @type {options } */
83
80
const defaults = { mode : 'push' , state : { } }
84
81
options = { ...defaults , ...options }
85
- const newUrl = $url ( path , userParams , options )
82
+ const newUrl = $url ( pathOrNode , userParams , options )
86
83
router . url [ options . mode ] ( newUrl , options . state )
87
84
return ''
88
85
} ,
@@ -91,7 +88,7 @@ export const goto = {
91
88
}
92
89
93
90
/**
94
- * @typedef {(<T extends string | HTMLAnchorElement>(
91
+ * @typedef {(<T extends string | RNodeRuntime | HTMLAnchorElement>(
95
92
* inputPath: T,
96
93
* userParams?: { [x: string]: string; },
97
94
* options?: Partial<$UrlOptions>
@@ -105,29 +102,16 @@ export const url = {
105
102
subscribe : ( run , invalidate ) => {
106
103
const { fragment, router } = contexts
107
104
108
- let InitialElem , initialParams , initialPath
109
-
110
- const createUrlString = createUrl ( fragment . fragment , router )
111
- const getInitialUrl = ( ) => createUrlString ( initialPath , ...initialParams )
112
-
113
105
return derived ( fragment . params , $params => {
114
- if ( InitialElem ) {
115
- // if we're dealing with an already set anchor element, set the href
116
- InitialElem . setAttribute ( 'href' , getInitialUrl ( ) )
117
- }
118
-
119
- // todo for some reason we always need to return this function, but it really shouldn't be necessary when an elem has been set
120
- return ( pathOrElem , ...params ) => {
106
+ return ( pathElemOrNode , params , options ) => {
107
+ const createUrl = getCreateUrl ( fragment . fragment , router )
121
108
// if we're dealing with a string, return the rendered url
122
- if ( typeof pathOrElem != 'object' ) {
123
- return createUrlString ( pathOrElem , ...params )
124
- }
125
-
126
- // if we're dealing with an anchor element, store it
127
- InitialElem = pathOrElem
128
- initialParams = params
129
- initialPath = InitialElem . getAttribute ( 'href' )
130
- InitialElem . setAttribute ( 'href' , getInitialUrl ( ) )
109
+ if ( ! ( pathElemOrNode instanceof HTMLAnchorElement ) )
110
+ return createUrl ( pathElemOrNode , params , options )
111
+
112
+ // if we're dealing with an anchor element, update it
113
+ const path = pathElemOrNode . getAttribute ( 'href' )
114
+ pathElemOrNode . setAttribute ( 'href' , createUrl ( path , $params , options ) )
131
115
}
132
116
} ) . subscribe ( run , invalidate )
133
117
} ,
@@ -146,7 +130,7 @@ export const url = {
146
130
* @param {Router } router
147
131
* @returns {UrlFromString }
148
132
*/
149
- export const createUrl =
133
+ export const getCreateUrl =
150
134
( fragment , router ) =>
151
135
/** @type {UrlFromString } */
152
136
( pathOrNode , userParams = { } , options = { } ) => {
0 commit comments