Skip to content

Commit

Permalink
Merge pull request #78 from ptlthg/fix/url-rewrite-double-navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthGigi authored Jan 8, 2025
2 parents ba10632 + ab72f54 commit c2cd5e7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
5 changes: 1 addition & 4 deletions src/lib/components/Navbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@
if (isIntersecting) {
let newHash;
newHash = "#" + element.id;
replaceState(newHash, {
...page,
url: { ...page.url, hash: newHash }
});
replaceState(newHash, page.state);
for (const link of navBarLinks) {
if (link.hash === newHash) {
activeSection = link.hash.slice(1);
Expand Down
7 changes: 4 additions & 3 deletions src/routes/stats/[ign]/[[profile]]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script lang="ts">
import { goto } from "$app/navigation";
import { replaceState } from "$app/navigation";
import { page } from "$app/state";
import { setProfileCtx } from "$ctx/profile.svelte";
import Main from "$lib/layouts/stats/Main.svelte";
import type { ValidStats } from "$types/stats";
import { untrack } from "svelte";
import { tick, untrack } from "svelte";
import type { PageData } from "./$types";
let { data }: { data: PageData } = $props();
Expand All @@ -28,7 +28,8 @@
// Update the URL to match the username and cute name
if (current !== wanted) {
const newUrl = page.url.toString().replace(current, wanted);
goto(newUrl, { replaceState: true });
// Tick to wait for the router to initialize
tick().then(() => replaceState(newUrl, page.state));
}
});
});
Expand Down

0 comments on commit c2cd5e7

Please sign in to comment.