Skip to content

Commit

Permalink
Correct i18n trailing slash redirect priority (#5306)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Oct 20, 2020
1 parent cc1cdbe commit 2474a80
Showing 1 changed file with 10 additions and 5 deletions.
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

0 comments on commit 2474a80

Please sign in to comment.