-
Hi, I am finding that when I use a redirect inside my I have tested a number of different methods of redirecting, but in its most basic form I have this: // next.config.js
module.exports = {
async redirects() {
return [{ source: '/((?!maintenance).*)', destination: '/maintenance', permanent: false }]
}
} Although the redirect seems to work to a degree, this causes the error in the browser console and I was wondering why this is? Just to note, I tried adding the following code inside a pages export async function getStaticProps() {
if (process.env.MAINTENANCE_MODE) {
return {
redirect: {
destination: '/maintenance',
permanent: false
}
}
}
.........
} which worked perfectly, however I dont really want to add this to my 20+ pages. If I could get the redirect working inside |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It's not properly a bug. By paying attention to what you did, you might see you're redirecting everything. That's why you're getting errors. All these lines will throw the error that you are mentioning in some clean page, for example: <script nomodule="" src="/_next/static/chunks/polyfills.js?ts=1619886952614"></script>
<script src="/_next/static/chunks/webpack.js?ts=1619886952614"></script>
<script src="/_next/static/chunks/main.js?ts=1619886952614"></script>
<script src="/_next/static/chunks/pages/_app.js?ts=1619886952614"></script>
<script src="/_next/static/chunks/pages/maintenance.js?ts=1619886952614"></script>
<script src="/_next/static/development/_buildManifest.js?ts=1619886952614"></script>
<script src="/_next/static/development/_ssgManifest.js?ts=1619886952614"></script> I see two ways that I would take it. async redirects() {
return [{
source: '/((?!maintenance|_next).*)',
destination: '/maintenance',
permanent: false }]
} If you need more paths, you have to add to maintenance|_next|img|video ... Or you can build some static HTML file an try this: async redirects() {
return [{
source: '/((?!maintenance).*)',
destination: '/maintenance.html',
permanent: false }]
} And then you need a maintenance.html file inside public: <!DOCTYPE html>
<html lang="en">
<head>
(...)
<title>Maintanence</title>
</head>
<body>(...)</body>
</html> It's going to work because you're out of Next.js context now, and all redirects will not work. I hope I was clear enough. |
Beta Was this translation helpful? Give feedback.
It's not properly a bug. By paying attention to what you did, you might see you're redirecting everything.
All requests inside your page it's going to be redirected, like scripts, images, etc.
That's why you're getting errors. All these lines will throw the error that you are mentioning in some clean page, for example: