layouts beforeload
I have a layout with a beforeload. As I navigate to children within this layout the beforeload is executed. Is there a way to configure this to run only once and not every time I navigate to different child routes?
4 Replies
stormy-gold•12mo ago
no, but you get the
cause
passed in. if it is "stay"
, you can skip the executionlike-goldOP•12mo ago
I have user auth data within a cookie. The idea is upon first visit to the app we ping our backend to verify if a valid cookie/session is present. This is done within an beforeload in _auth layout. The downside is that as im navigating through the app the beforeload is constantly being triggered and again when I navigate to a child route.
I was thinking about after the initial beforeload saving the user in some auth state then just have a condition at the top of the beforeload for _app to check if a user session is valid. If user is null then ping the server to validate the cookie.
What are your thoughts 🤔
@Manuel Schiller
stormy-gold•12mo ago
does my suggestion not fit your needs?
like-goldOP•12mo ago
Actually hold on it might
I have preload intent so i need to check for preload and stay. That should do the trick maybe