Comments (4)
Well if you log stuff, you will see strange behavior, it does not add locale to the URL for default locale, but does for other ones.
If you do:
url.pathname = `/${locale}/_sites/${currentHost}${pathname}`;
then your default one will work, but you'll get 404 on all others. And reason is that other locales are added twice, once by you, and once by system. I solved it by adding this:
const { pathname, locale, defaultLocale } = req.nextUrl;
.
.
.
if (currentHost == "app") {
if (
pathname === "/login" &&
(req.cookies["next-auth.session-token"] ||
req.cookies["__Secure-next-auth.session-token"])
) {
url.pathname = `/${locale}`;
return NextResponse.redirect(url);
}
url.pathname = `/${locale}/app${pathname}`;
return NextResponse.rewrite(url);
}
if (hostname === "localhost:3000" || hostname === "yourdomain.something") {
url.pathname = `/${locale}/home${pathname}`;
return NextResponse.rewrite(url);
}
if (locale === defaultLocale) {
url.pathname = `/${locale}/_sites/${currentHost}${pathname}`;
return NextResponse.rewrite(url);
}
url.pathname = `/_sites/${currentHost}${pathname}`;
return NextResponse.rewrite(url);
}
Hope it helps
from platforms.
im having the exact same issue when using i18n
from platforms.
Hey guys! Sorry for the late response but this should've been fixed in the latest version of Next.js. Feel free to reference this issue here: vercel/next.js#36563
from platforms.
The problem still exists:
nextjs version
"next": "13.2.4",
middleware code:
import { NextRequest, NextResponse } from "next/server";
export const config = {
matcher: [
"/((?!api/|_next/|_static/|/|[\\w-]+\\.\\w+).*)",
],
};
export default async function middleware(req: NextRequest) {
const url = req.nextUrl;
const hostname = req.headers.get("host") || "demo.localhost:3000";
const path = url.pathname;
return NextResponse.rewrite(
new URL(`/_sites/${currentHost}${path}`, req.url)
);
}
nextconfig code
/**
* @format
* @type {import('next').NextConfig}
*/
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
const nextConfig = {
reactStrictMode: true,
poweredByHeader: false,
i18n: {
localeDetection: false,
locales: ['en', 'cn', 'jp', 'it', 'tw', 'kr', 'hk', 'fr'],
defaultLocale: 'cn',
}
};
module.exports = withBundleAnalyzer(nextConfig);
The problem still exists
from platforms.
Related Issues (20)
- .science domain not support by GUI HOT 1
- Upgrade next auth to v5 HOT 1
- Server Action rejected on localhost due to origin policy of Next.js 14
- Hi, when adding new folders and files
- Added path to ignore returns 404 HOT 1
- Next 14.0.2 Github OAuthCallbackError 'State cookie was missing' in local development HOT 2
- how to settle internal conflicts on domain claims within the platform
- getting DNS_PROBE_FINISHED_NXDOMAIN on my custom domain HOT 2
- Error occurred in prerendering individual site pages! in production
- Post view page generates infinite network requests HOT 2
- Custom domain should not be unique
- Desperate need for help... The Middleware behaves unpredictabily and I can't get hostname HOT 5
- Adding NextAuth
- Bug: Adding a custom domain with an initial misconfigured DNS config keeps staying in error mode forever
- request headers host unexpectedly changed
- Error when deploying Django App on Vercel
- How to load different UI configurations based on the tenant? HOT 5
- how to invalidate all a pages of a [domain] route
- Title and description fields within the post editor do not trigger the save function as expected, also infinite loop on editor page related to nav.tsx HOT 4
- How to get this to work with next-auth v5? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from platforms.