@@ -68,8 +68,8 @@ export function createRouter(
68
68
if ( ( await router . onBeforeRouteChange ?.( href ) ) === false ) return
69
69
if ( inBrowser && href !== normalizeHref ( location . href ) ) {
70
70
// save scroll position before changing url
71
- history . replaceState ( { scrollPosition : window . scrollY } , document . title )
72
- history . pushState ( null , '' , href )
71
+ history . replaceState ( { scrollPosition : window . scrollY } , '' )
72
+ history . pushState ( { } , '' , href )
73
73
}
74
74
await loadPage ( href )
75
75
await router . onAfterRouteChanged ?.( href )
@@ -111,7 +111,7 @@ export function createRouter(
111
111
if ( actualPathname !== targetLoc . pathname ) {
112
112
targetLoc . pathname = actualPathname
113
113
href = actualPathname + targetLoc . search + targetLoc . hash
114
- history . replaceState ( null , '' , href )
114
+ history . replaceState ( { } , '' , href )
115
115
}
116
116
117
117
if ( targetLoc . hash && ! scrollPosition ) {
@@ -162,6 +162,9 @@ export function createRouter(
162
162
}
163
163
164
164
if ( inBrowser ) {
165
+ if ( history . state === null ) {
166
+ history . replaceState ( { } , '' )
167
+ }
165
168
window . addEventListener (
166
169
'click' ,
167
170
( e ) => {
@@ -203,7 +206,7 @@ export function createRouter(
203
206
// scroll between hash anchors in the same page
204
207
// avoid duplicate history entries when the hash is same
205
208
if ( hash !== currentUrl . hash ) {
206
- history . pushState ( null , '' , href )
209
+ history . pushState ( { } , '' , href )
207
210
// still emit the event so we can listen to it in themes
208
211
window . dispatchEvent (
209
212
new HashChangeEvent ( 'hashchange' , {
@@ -228,6 +231,9 @@ export function createRouter(
228
231
)
229
232
230
233
window . addEventListener ( 'popstate' , async ( e ) => {
234
+ if ( e . state === null ) {
235
+ return
236
+ }
231
237
await loadPage (
232
238
normalizeHref ( location . href ) ,
233
239
( e . state && e . state . scrollPosition ) || 0
0 commit comments