You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This could all go into a file at the base route of all of these and execute every time.
Another example is with dynamic route segments. Say you have a dynamic segment called [id] and for every route beyond that you want to get some data from a database based solely on that id (user etc). This could be fetched at the base of this dynamic segment to fetch the data and give it to the route handler.
Proposal
Have a file called something (I don't care what it is called). This file can have the following exports:
default: Runs on every request (for routes beyond it) METHOD: Runs on every request with that method (useful for api routes)
This functions inside this file can return two things:
Response: This response is sent to the client immediately (can be jsx for page.ts)
An object containing variables: these variables get sent to the route handler
These functions are always run on the server, and parsed all variables the route handler would.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Background
Reduces code duplication. I have a app, with the first four lines of 1/3 of my api endpoints are:
This could all go into a file at the base route of all of these and execute every time.
Another example is with dynamic route segments. Say you have a dynamic segment called
[id]
and for every route beyond that you want to get some data from a database based solely on that id (user etc). This could be fetched at the base of this dynamic segment to fetch the data and give it to the route handler.Proposal
Have a file called something (I don't care what it is called). This file can have the following exports:
default
: Runs on every request (for routes beyond it)METHOD
: Runs on every request with that method (useful for api routes)This functions inside this file can return two things:
Response
: This response is sent to the client immediately (can be jsx forpage.ts
)These functions are always run on the server, and parsed all variables the route handler would.
Beta Was this translation helpful? Give feedback.
All reactions