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 URL rewriting causing a second navigation/page load #78

Merged
Merged
Show file tree
Hide file tree
Changes from all 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: 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
Loading