Next.js Discord

Discord Forum

How to pass some property to all routes in next.js?

Unanswered
Common Raven posted this in #help-forum
Open in Discord
Common RavenOP
### Hello! 👋

I use custom server.js and i'm trying find a way to pass custom properties to next.js pages.
For example,
const someProperty = '123';

if (pathname === '/example') {
        await app.render(req, res, '/example', query)
      }

I need somehow pass someProperty to /example page and have access to it in getServerSideProps of page. Is it possible? If yes, how to do that?

P.S. Found similar question on [StackOverflow](https://stackoverflow.com/questions/68595971/how-to-pass-data-from-express-server-with-nextjs-to-a-page), which works for me, but i wonder, if it's correct and safe way to pass sensitive data? Does data passed in that way is stay server side until i return it from getServerSideProps? Maybe next.js have a better way to do this? Just need to clarify.

Sorry for dumb questions, i'm new to next.js, just finished some react course and just play around and experimenting with next.js. Also sorry for my english if it sounds stupid and incorrect. :box_cat_hide:

1 Reply

Common RavenOP
up