Search code examples
routessveltesveltekitpage.js

How to call parent +page.js from more specific route in SvelteKit?


I'm using SvelteKit to develop an application, and I want to call the parent route's (i.e. / from /products) +page.js on page load, however it simply doesn't call it, despite not having a +page.js in /products.

This is how my file system looks:

src/routes
- +page.js (I want to call this)
- +page.svelte
- +layout.svelte
src/routes/products
-     +page.svelte (I want this to call it)

Solution

  • You may need to make a +page.js file in your products and import and call the load function from manually.

    EDIT: You can run a load function from the layout in src/routes and this may be a better solution. So just rename +page.js to +layout.js.