GithubHelp home page GithubHelp logo

sveltekit-tutorial's Issues

[lesson 10] page.params.id

when i typed in the code that you showed in the video[lesson 10]:

<script context="module">
  export async function load({ page, fetch }) {
    const id = page.params.id
    const res = await fetch(`https://jsonplaceholder.typicode.com/posts/${id}`)
    const guide = await res.json()
    if (res.ok) {
      return {
        props: {
          guide
        }
      }
    }
    return {
      status: res.status,
      error: new Error('Could not fetch that guide')
    }
  }
</script>

I got a error:

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

so I use this code to check the arguments:

export async function load({ fetch}) {
    console.dir(arguments);  
}

and finally I know how to get the 'id' by using following code:

<script context="module">
  export async function load({ fetch, params }) {
    console.dir(arguments);  //遇到报错的时候可以用console把参数全部打印出来看看
    const id = params.id;
    const res = await fetch(`https://jsonplaceholder.typicode.com/posts/${id}`);
    const guide = await res.json();

    if (res.ok) {
      return {
        props: {
          guide,
        },
      };
    }

    return {
      status: res.status,
      error: new Error("Could not fetch the guide"),
    };
  }
</script>

Hopefully this can help others with the same bug.(๑′ᴗ‵๑)I Lᵒᵛᵉᵧₒᵤ❤

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.