Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix client side router issue with handling hash #3757

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chatty-ducks-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Prevent full reload when router navigates and only removes hash
3 changes: 2 additions & 1 deletion packages/kit/src/runtime/client/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ export class Router {
if (a instanceof SVGAElement ? a.target.baseVal : a.target) return;

// Check if new url only differs by hash
benmccann marked this conversation as resolved.
Show resolved Hide resolved
if (url.href.split('#')[0] === location.href.split('#')[0]) {
const [base, hash] = url.href.split('#');
if (hash && base === location.href.split('#')[0]) {
// Call `pushState` to add url to history so going back works.
// Also make a delay, otherwise the browser default behaviour would not kick in
setTimeout(() => history.pushState({}, '', url.href));
Expand Down