You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But when I access to /, it doesn't redirect me in the app into /en.
However, it work with /en/about > /about, and it work within the app.
To Reproduce
Use [lang] as parameters and have a [lang] directory
server.js
const { createServer } = require("http");
const { parse } = require("url");
const next = require("next");
// locales = ['en','fr']
const { locales } = require("./translations/config");
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare().then(() => {
createServer((req, res) => {
// Be sure to pass `true` as the second argument to `url.parse`.
// This tells it to parse the query portion of the URL.
const parsedUrl = parse(req.url, true);
const { pathname, query } = parsedUrl;
const pathNameSplit = pathname.split("/");
if (
(pathNameSplit[pathNameSplit.length - 1].indexOf(".") < 0 &&
pathname.indexOf("_next/webpack-hmr") < 0) ||
!pathname
) {
if (locales.indexOf(pathname.slice(1, 3)) < 0) {
// Display english version if the lang is not detected
console.log("Render", `/en/${pathname.slice(1)}`);
app.render(req, res, `/en/${pathname.slice(1)}`, query); // Here is my issue /en is not redirected to /en in the app but to /
} else if (pathname.slice(1, 4) === "en/" || pathname == "/en") {
res.writeHead(301, { Location: `/${pathname.slice(4)}` });
return res.end();
}
}
handle(req, res, parsedUrl);
}).listen(3001, err => {
if (err) throw err;
console.log("> Ready on http://localhost:3001");
});
});
The text was updated successfully, but these errors were encountered:
This is more so a question which belongs on https://spectrum.chat/next-js. When creating issues please make sure a clear and concise full reproduction is provided otherwise it becomes incredibly hard to help.
I guess this specifically will be covered by #9081
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
vercel
locked as resolved and limited conversation to collaborators
Jan 30, 2022
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Bug report
Describe the bug
I use the parameters [langs] in my project to use multi lang.
So If I can easily access: /fr /fr/about, /en, /en/about
Thing is, I want my default locale to redirect to / and /about.
So I use a custom router to do that and the following method:
But when I access to /, it doesn't redirect me in the app into /en.
However, it work with /en/about > /about, and it work within the app.
To Reproduce
The text was updated successfully, but these errors were encountered: