Questions tagged [sveltekit]

[SvelteKit](https://kit.svelte.dev/) is a framework for building fullstack web applications with the Svelte framework.

SvelteKit is a framework for building fullstack web applications with the Svelte framework.

2260 questions
47
votes
4 answers

How to route programmatically in SvelteKit?

I want to be able manage history of my SvelteKit app while simultaneously making sure the whole routing system of SvelteKit doesn't get affected in any way. Something like: function routeToPage(route: string) { router.push(`/${route}`) //…
Himujjal
  • 1,581
  • 1
  • 14
  • 16
29
votes
4 answers

npm run dev --host network: not exposed

I want to expose my svelte app on LAN using the npm run dev --host command but it shows: > frontend@0.0.1 dev > svelte-kit dev SvelteKit v1.0.0-next.295 local: http://localhost:3000 network: not exposed Use --host to expose server to…
blest
  • 437
  • 1
  • 4
  • 10
29
votes
4 answers

SvelteKit: how do I do slug-based dynamic routing?

I am a newbie on Svelte and in coding in general. I'd prefer to learn SvelteKit (Svelte@Next) rather than sapper since that seems to be where Svelte is heading. For my personal project, I need to support dynamic routing based on url slugs. How do I…
Johny Chen
  • 301
  • 1
  • 3
  • 3
28
votes
3 answers

How do get query string parameter in sveltekit?

I'm trying to the /login?ref=/some/path parameter to redirect to after login: const ref = $page.url.searchParams.get('ref') || '/dashboard'; However I get this error: TypeError: Cannot read properties of undefined (reading 'searchParams')
chovy
  • 72,281
  • 52
  • 227
  • 295
24
votes
1 answer

config.kit.adapter should be an object with an "adapt" method

I want to use the @sveltejs/adapter-static in my Svelte Kit app (want to turn it into an SPA). I installed the adapter static with npm i @sveltejs/adapter-static. The code in the svelte.config.cjs looks like this kit: { // By default, `npm run…
Fugi
  • 466
  • 8
  • 18
23
votes
4 answers

Cross-site POST form submissions are forbidden

My sveltekit app has a form which sends a POST request to server. The app is working fine on dev server but when I build and run the app it fails to send the form data via POST request. It shows the following error in the browser: Cross-site POST…
Shakir
  • 270
  • 2
  • 11
23
votes
2 answers

SSR explained in SvelteKit

I recently started working with Svelte via SvelteKit and I have a few questions about this framework to which I haven't been able to find any direct answers in the source/documentation: SvelteKit has SSR and in the documentation it says: All…
21
votes
2 answers

How to add a custom 404 page and a different Error page (for other errors) in SvelteKit?

Basically, how to do the ff. in SvelteKit: Add a custom 404 page first. Have a different generic Error page that will show a message/description about the error in SvelteKit
Zedd
  • 2,069
  • 2
  • 15
  • 35
21
votes
1 answer

SvelteKit: How to output build as single HTML file with inlined JS and CSS?

Is it possible to build a SvelteKit project to a single output HTML file which inlines all JS and CSS? Could SvelteKit be configured to support this output format or do I need to use an external build tool? The single HTML file output is a core…
Samuel Plumppu
  • 325
  • 2
  • 13
19
votes
3 answers

SvelteKit: disable SSR

I made an app in Svelte and now I wanted to port it to SvelteKit. My app uses window and document objects, but those aren't available in SSR. Firstly, it threw ReferenceError: window is not defined, but I fixed that by checking if the app is running…
Libertas
  • 358
  • 2
  • 5
  • 11
18
votes
2 answers

SvelteKit, import type LayoutServerLoad/PageLoad

In layout.server.ts I try to import type { LayoutServerLoad } from './$types'; but the type can't be found: '"./$types"' has no exported member named 'LayoutServerLoad'. Did you mean 'LayoutServerData'? What do I need to do to get the type…
Nausika
  • 495
  • 7
  • 13
17
votes
3 answers

cannot find package sveltejs/adapter-auto svelte.config.js

I am new to SvelteKit and have built an initial project from the SvelteKit docs. When the project opens I receive the following error when looking at index.svelte. Error in svelte.config.js Error [ERR_MODULE_NOT_FOUND]: Cannot find…
jonthornham
  • 2,881
  • 4
  • 19
  • 35
17
votes
4 answers

Where to put images with SvelteKit

I have been using Svelte for a little while and now I have switched to SvelteKit so I can add multiple pages. I want to add some images to my site but I don't know where to put them. In Svelte I would just put them in public/images but there is no…
Anders
  • 663
  • 1
  • 4
  • 14
16
votes
2 answers

How can I tell whether SvelteKit's "load" function is running on the server vs. client?

I'm trying to do API calls in a SvelteKit page from the load function, but I don't want to proxy these calls with local endpoints because I want to keep the web server as light as possible. What I want to do specifically is, when the call is made…
cambraca
  • 27,014
  • 16
  • 68
  • 99
15
votes
2 answers

visible, non-interactive elements with an on:click event must be accompanied by an on:keydown, on:keyup, or on:keypress event

A11y: visible, non-interactive elements with an on:click event must be accompanied by an on:keydown, on:keyup, or on:keypress event.svelte (a11y-click-events-have-key-events) what does this error mean ? I am getting it too much in sveltekit. When…
H Nazmul Hassan
  • 631
  • 2
  • 8
  • 17
1
2 3
99 100