File tree 2 files changed +10
-2
lines changed
packages/kit/src/runtime/client
2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @sveltejs/kit ' : patch
3
+ ---
4
+
5
+ Prevent full reload when router navigates and only removes hash
Original file line number Diff line number Diff line change @@ -184,8 +184,11 @@ export class Router {
184
184
// Ignore if <a> has a target
185
185
if ( a instanceof SVGAElement ? a . target . baseVal : a . target ) return ;
186
186
187
- // Check if new url only differs by hash
188
- if ( url . href . split ( '#' ) [ 0 ] === location . href . split ( '#' ) [ 0 ] ) {
187
+ // Check if new url only differs by hash and use the browser default behavior in that case
188
+ // This will ensure the `hashchange` event is fired
189
+ // Removing the hash does a full page navigation in the browser, so make sure a hash is present
190
+ const [ base , hash ] = url . href . split ( '#' ) ;
191
+ if ( hash && base === location . href . split ( '#' ) [ 0 ] ) {
189
192
// Call `pushState` to add url to history so going back works.
190
193
// Also make a delay, otherwise the browser default behaviour would not kick in
191
194
setTimeout ( ( ) => history . pushState ( { } , '' , url . href ) ) ;
You can’t perform that action at this time.
0 commit comments