Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
Sveltekit Error: `page` in `load` functions has been replaced by `url` and `params`

I am trying to display my date from GraphCMS in my blog application. I receive this error when I go to my single post link (http://localhost:3000/posts/union-types-and-sortable-relations)

"

page in load functions has been replaced by url and params Error: page in load functions has been replaced by url and params

"

Here is my code

<script context='module'>
    export const load = async ({fetch, page: {params}}) => {
        const {slug} = params
        const res = await fetch(`/posts/${slug}.json`)
        if(res.ok) {
            const {post} = await res.json()
            return {
                props: {post},
            }
        }
    }
</script>

<script>
    export let post
</script>


<svelte:head>
    <title>Emrah's Blog | Welcome</title>
</svelte:head>

<pre>{JSON.stringify(post, null, 2)}</pre>

Can you please help. Thanks

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Try using params instead of page: params, though the latter still works in Sveltekit 278 (which I'm using). Besides, I'm curious to know what makes you prefer this method to querying GraphCMS for your single post. I do it like this:

import {client} from '$lib/js/graphql-client'
import {projectQuery} from '$lib/js/graphql-queries'

export const load = async ({ params }) => {
        const {slug} = params
        const variables = {slug}
        const {project} = await client.request(projectQuery, variables)

        return {
            props: {
                project
            }
        }
    }
about 4 years ago · Juan Pablo Isaza Relatório

0

Yes, this has been changed a while ago, now the different parts of what used to be page are passed directly into the load function:

export async function load({ fetch, page }) {
 const { params, url } = page
}

export async function load({ fetch, params, url }) {
}

Something else to consider is that now there are page endpoints, if your file is [slug].svelte you can make a file [slug].js and add the following:

export async function get({ params }) {
  const { slug } = params;
  const post = {}; // add the code to fetch from GraphCMS here
  return {
    status: 200,
    body: {
      post
    }
  }
}

With this you can remove the load function and make your code simpler (especially because you technically already have all this code in your /posts/[slug].json.js file.

about 4 years ago · Juan Pablo Isaza Relatório

0

<script context='module'>
export async function load({ fetch, params}){
   
   
    let id = params.users
    const response = await fetch(`https://jsonplaceholder.typicode.com/users/${id}`)
    const user = await response.json()
   
    if(response.ok){
        return  {props:{user}}
    }
    return {
        status: response.status,
        error : new Error(" sorry no user found")
    }
    }
      
    
export let user

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda