Skip to content
This repository has been archived by the owner on May 10, 2021. It is now read-only.

Commit

Permalink
Force redirects with conditions before plain redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
FinnWoelm committed Jan 17, 2021
1 parent cce9b57 commit e9172ad
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/steps/setupRedirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ const setupRedirects = (publishPath) => {
// Sort routes: More-specific routes precede less-specific routes (e.g., catch-all)
const getSortedRedirects = (redirects) => {
const sortedRoutes = getSortedRoutes(redirects.map(({ route }) => route));
return redirects.sort(
(a, b) => sortedRoutes.indexOf(a.route) - sortedRoutes.indexOf(b.route)
);
return redirects.sort((a, b) => {
// If routes are different, sort according to Next.js' getSortedRoutes
if (a.route !== b.route)
return sortedRoutes.indexOf(a.route) - sortedRoutes.indexOf(b.route);

// Otherwise, put the route with more conditions first
return (b.conditions || []).length - (a.conditions || []).length;
});
};
const sortedStaticRedirects = getSortedRedirects(staticRedirects);
const sortedDynamicRedirects = getSortedRedirects(dynamicRedirects);
Expand Down

0 comments on commit e9172ad

Please sign in to comment.