tmonaco
tmonaco
Explore posts from servers
TTCTheo's Typesafe Cult
Created by tmonaco on 8/14/2024 in #questions
Redirects in next.config.js - App Router - NextJS 14
Hi guys, I was wondering how can I make a redirect with a nagavite lookahead in the slug. Let's say I have these two routes: - /blog/new - /blog/:id/overview What I want to do is, if you input in the URL /blog/:id I want to redirect the user to /blog/:id/overview. The problem is that if I include this in the next.config.js I cannot navigate to /blog/new because new is being inferred as the slug.
const nextConfig = {
async redirects() {
return [
{
source: "/blog/:id",
destination: "/blog/:id/overview",
permanent: true,
}
];
},
};
const nextConfig = {
async redirects() {
return [
{
source: "/blog/:id",
destination: "/blog/:id/overview",
permanent: true,
}
];
},
};
I tried to use this regex in the slug, but it didn't work...
const nextConfig = {
async redirects() {
return [
{
source: "/blog/:id(^(?!new$).*)",
destination: "/blog/:id/overview",
permanent: true,
}
];
},
};
const nextConfig = {
async redirects() {
return [
{
source: "/blog/:id(^(?!new$).*)",
destination: "/blog/:id/overview",
permanent: true,
}
];
},
};
Any idea of how can I achieve this or if there is a better way of doing it? Also this is my file tree:
blog/
├── [id]/
│ └── overview/
│ └── page.tsx
└── new/
└── page.tsx
blog/
├── [id]/
│ └── overview/
│ └── page.tsx
└── new/
└── page.tsx
2 replies
TTCTheo's Typesafe Cult
Created by tmonaco on 7/3/2024 in #questions
Redirect and Middleware rewrites
Hi guys, I got a question that might be silly or not but is regarding the NextJS redirect and rewrites in the middleware in v 14.2.4. So I have a multi-tenant app, and in my middleware is where I rewrite my NextResponse (“NextResponse.rewrite()”). I'm using the tenant as a subdomain, so let's say that my local url looks like this: http://mytenant.localhost:3000/. So I have a case where I'm using redirect() from next-navigation to send the user to redirect('/the-redirect-url/foo/faa'). In the middleware when I want to grab that subdomain from the req.headers.get('host') I just got localhost as a host, while if I just reload a page from my subdomain, I do get mytenant.localhost as the host. So, what'm I doing wrong? Any hints or modifications? Did I miss something? Also, because I’m rewriting the response in my middleware, should I be using “x-forwarded-host” instead of “host”? If I do, it works fine, so it is safe? (I’m using the redirect in a server action)
2 replies
TTCTheo's Typesafe Cult
Created by tmonaco on 6/19/2024 in #questions
ESLint config
Hey guys, recently I watched one of Theo’s videos where he mention sth about the eslint-config plugin. He mentioned the fact that this Airbnb config “standard” is not really useful, even Airbnb itself does not use it. So happy to hear opinions about good ESLint rules for NextJS with prettier project…
7 replies