Disable a route at build time
Unanswered
Balinese posted this in #help-forum
BalineseOP
Hey all,
I'm wondering whether there is a way to completely disable a route at build time, so that it never gets registered in the first place. Something like passing an environment variable at the time of building, and that changing whether the route gets registered. Lets say the app looks like this:
Would there be a way for me to disable the
I'm wondering whether there is a way to completely disable a route at build time, so that it never gets registered in the first place. Something like passing an environment variable at the time of building, and that changing whether the route gets registered. Lets say the app looks like this:
- /app
| - /togglable_route
| | - page.tsx
| page.tsx
Would there be a way for me to disable the
/togglable_route
at build time? Maybe make it so it's only enabled whenever I pass a special environment variable like ENABLE_MY_SECRET_ROUTE
? I know I could just check for this variable at runtime, but that not only seems like a waste of time, I would also imagine that it's going to ship more unnecessary JavaScript to the client. Additionally, if there are many more routes under this specific route, and I would want to disable them all, it doesn't really seem like a feasible solution, as one could miss a single if statement and expose a certain route.1 Reply
Giant panda
Yes, you can conditionally disable a route at build time. One way to do this is by using a dynamyc next.config.js file and environment variables. This approach lets you change your application's configuration and routes before the build even start
You can modify your next.config.js file to check for an environment variable. Based on this variable, you can exclude specific pages or directories from the build process.
You can add prebuild condition and on that remove one folder for the build to start
You can modify your next.config.js file to check for an environment variable. Based on this variable, you can exclude specific pages or directories from the build process.
You can add prebuild condition and on that remove one folder for the build to start