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

Why does "Select.svelte" appear on Sveltekit [slugs] params? #638

Open
ichwanulfadhli opened this issue Oct 18, 2023 · 0 comments
Open

Why does "Select.svelte" appear on Sveltekit [slugs] params? #638

ichwanulfadhli opened this issue Oct 18, 2023 · 0 comments

Comments

@ichwanulfadhli
Copy link

I'm currently developing a form page which has Svelte Select in it.

Here the example of the page code:
+page.svelte

<form method="POST" bind:this={forms} use:enhance>
	<Select 
		name="select" 
		on:change={()=> forms.requestSubmit()}
		showChevron={true}
		class="dark:!text-white dark:!bg-gray-700 !bg-gray-50"
		placeholder="Pilih atau cari nama sekolah"
		items={items}
	/>
</form>

In order to display the items on to the <Select /> component, I loaded them in the +page.server.ts file
+page.server.ts

import environment from '$src/lib/services/environment';

import { fail, redirect } from '@sveltejs/kit';
import type { Actions, PageServerLoad } from './$types';

export const load: PageServerLoad = async ({ fetch, params }) => {
    console.log(params);


    const res = await fetch(`${environment.apiUrl}/dashboard/${params.halaman}`);
    const item = await res.json();

    return { item };
};

Here's the thing. When the page is loaded, it's giving me an error SyntaxError: Unexpected token < in JSON at position 0. I console log the params argument and it shows this
image
Even though I got an error, the <Select /> component is still displaying the data.
image

When I navigate to other page, and back again to this page, the [slugs] is back to normal as it should be
image

Any idea why or how to solve this?
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant