Cannot read properties of undefined (reading 'params') sveltkit

Viewed 31

i just upgrade svelte migration route then create +page.js file this script

export async function load({ page }) {
   var songId = page.params.songId;
   const itunesSearched = await fetch(
    `https://itunes.apple.com/search?term=${songId}&entity=song`
  );
  var res = await itunesSearched.json();
  var songResults = res.results[0];
  return {songResults}
}

Error below

Cannot read properties of undefined (reading 'params')
TypeError: Cannot read properties of undefined (reading 'params')
    at load (/src/routes/[searched]/[songId]/+page.js:2:22)
1 Answers

You can see the interface of the event data in the docs. It has no page property; params are a direct property of the event, so you should be able to just destructure that:

export async function load({ params }) { ...
Related