Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[next] Correct i18n trailing slash redirect priority #5306

Merged
merged 2 commits into from Oct 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions packages/now-next/src/index.ts
Expand Up @@ -10,7 +10,7 @@ import {
PrepareCacheOptions,
Prerender,
} from '@vercel/build-utils';
import { Handler, Route } from '@vercel/routing-utils';
import { Handler, Route, Source } from '@vercel/routing-utils';
import {
convertHeaders,
convertRedirects,
Expand Down Expand Up @@ -1968,22 +1968,27 @@ export const build = async ({
...headers,

// redirects
...redirects.map(redir => {
...redirects.map(_redir => {
if (i18n) {
const redir = _redir as Source;
// detect the trailing slash redirect and make sure it's
// kept above the wildcard mapping to prevent erroneous redirects
// since non-continue routes come after continue the $wildcard
// route will come before the redirect otherwise and if the
// redirect is triggered it breaks locale mapping

const location =
redir.headers && (redir.headers.location || redir.headers.Location);

if (
redir.status === 308 &&
(redir.dest === '/$1' || redir.dest === '/$1/')
(location === '/$1' || location === '/$1/')
) {
// we set continue true
(redir as any).continue = true;
redir.continue = true;
}
}
return redir;
return _redir;
}),

...(i18n
Expand Down