Skip to content

Commit c17838f

Browse files
committed
resolve internal links to support dynamic base path
1 parent 3eb3a40 commit c17838f

5 files changed

Lines changed: 14 additions & 9 deletions

File tree

src/routes/(authed)/+layout.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { resolve } from "$app/paths";
12
import type { LayoutLoad } from "./$types"
23
import { redirect } from "@sveltejs/kit";
34

45
export const load: LayoutLoad = async ({ parent }) => {
56
const { spotify } = await parent()
6-
if (!spotify.user) redirect(303, "/");
7+
if (!spotify.user) redirect(303, resolve("/"));
78
}

src/routes/(authed)/playlists/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
</div>
3333
{/each}
3434

35-
<!-- <a class="playlist wireframe" href="/create-playlist">+</a> -->
35+
<!-- <a class="playlist wireframe" href={resolve("/create-playlist")}>+</a> -->
3636
</main>

src/routes/+layout.svelte

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import type { Snippet } from 'svelte';
33
import GithubLogo from 'virtual:icons/logos/github-icon';
44
import './styles.css';
5+
import { resolve } from '$app/paths';
56
67
let { data, children } = $props();
78
</script>
@@ -18,10 +19,10 @@
1819
<header
1920
class="relative grid grid-cols-[repeat(2,max-content)_1fr] justify-items-end items-center gap-8 overflow-scroll pb-8 px-8"
2021
>
21-
<a href="/"
22-
><img src="favicon.png" alt="autofy icon" class="h-8 aspect-square rounded-full" /></a
23-
>
24-
<a class="autofy font-black text-[2rem]" href="/">autofy</a>
22+
<a href={resolve('/')}>
23+
<img src="favicon.png" alt="autofy icon" class="h-8 aspect-square rounded-full" />
24+
</a>
25+
<a class="autofy font-black text-[2rem]" href={resolve('/')}>autofy</a>
2526

2627
{#if data.spotify.user}
2728
{#if data.spotify.user.image}

src/routes/+layout.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { LayoutLoad } from "./$types";
22
import { SignIn as SpotifySignIn, SignOut as SpotifySignOut } from "$lib/spotify";
33
import { spotify } from "$lib/state.svelte";
44
import { goto } from "$app/navigation";
5+
import { resolve } from "$app/paths";
56

67
export const ssr = false;
78
export const prerender = true;
@@ -13,11 +14,11 @@ export const load: LayoutLoad = async ({ url }) => {
1314

1415
async function SignIn() {
1516
spotify.user = await SpotifySignIn()
16-
goto("/playlists")
17+
goto(resolve("/playlists"))
1718
}
1819

1920
async function SignOut() {
2021
await SpotifySignOut()
2122
spotify.user = null
22-
goto("/")
23+
goto(resolve("/"))
2324
}

src/routes/+page.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script lang="ts">
2+
import { resolve } from '$app/paths';
3+
24
let { data } = $props();
35
46
const BUTTON_CLASS =
@@ -23,7 +25,7 @@
2325
</p>
2426

2527
{#if data.spotify.user}
26-
<a href="/playlists" class={BUTTON_CLASS}> my&nbsp;playlists </a>
28+
<a href={resolve('/playlists')} class={BUTTON_CLASS}> my&nbsp;playlists </a>
2729
{:else}
2830
<button onclick={data.SignIn} class={BUTTON_CLASS}>
2931
connect&nbsp;your&nbsp;Spotify&nbsp;account to&nbsp;get&nbsp;started!

0 commit comments

Comments
 (0)