1

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)
Basil
  • 488
  • 1
  • 15
  • I think `page.js` files are not meant to run / be called independent from their route. You might want to include what kind of logic is in there that you need to be executed from the subroute – Corrl Sep 07 '22 at 15:26
  • @Corrl It basically loads the user information so it can display the user's name in the top bar etc. It works fine when using svelte routing, since I store that info in a store once it's loaded, however when I go direct to `/products` (i.e. in the URL bar), it doesn't load this and instead my placeholder text shows – Basil Sep 07 '22 at 15:35
  • Better add the info to your question and notify via a comment of the update (I think the main question is "where to put initial logic which should be executed indepent of the entry route") – Corrl Sep 07 '22 at 15:53

1 Answers1

3

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.

justintimeza
  • 1,064
  • 4
  • 8