kit
kit copied to clipboard
Determine if Page or Layout from within the load function
Describe the problem
There should be a way to determine from within a load function inside a +page.ts file or +layout.ts whether
the load function is being called for a page or layout.
I am making a 3rd party library that is intended to be used only inside load functions. But I need to know cleanly (i.e. without user directly informing my library), whether it is being called for a layout or page.
Describe the proposed solution
I don't have a nice solution.
One solution is:
export async function load(x) {
x.layout = true/false <---- implying whether it is a layout or page.
const { routeId, params } = x;
}
Alternatives considered
No response
Importance
would make my life easier
Additional Information
No response
Does anyone know some kind of hack or workaround?
Could you provide more info/details what you library does, what the API is and how it's invoked?
@dummdidumm
- Currently sveltekit only works with node.js backends.
- My library allows sveltekit (in static mode) to be used with any backend language.
- To facilitate this, the library makes a HTTP request to an arbitrary backend with details such as the route name, route params etc and the backend will return a JSON response, intended to be the return value of the
loadfunction. - The issue is when a page has a
page.tsandlayout.ts. Both will call it's ownloadfunction. - The arbitrary backend will need to differentiate the two separate requests since all other details (i.e. route name, route params etc) are identical.
- Currently my library is requesting manual intervention via the developer setting if the load is inside a page or layout.
- Hence the request for some kind of flag.