import settings from 'settings'; import { getUrlPathWithLocale } from './localization'; type IgnorePath = string | RegExp; const defaultIgnoreList: string[] = []; const extraIgnores: IgnorePath[] = Array.isArray( settings.commerceRedirectionIgnoreList ) ? settings.commerceRedirectionIgnoreList.map((path) => { if (path === '/users/reset') { return /^\/users\/reset\/[^/]+\/[^/]+\/$/; } return path; }) : []; export function shouldIgnoreRedirect( pathname: string, locale: string ): boolean { if (!pathname) return false; const rawIgnoreList: IgnorePath[] = [...defaultIgnoreList, ...extraIgnores]; return rawIgnoreList.some((ignorePath) => { if (ignorePath instanceof RegExp) { return ignorePath.test(pathname); } const localized = getUrlPathWithLocale(ignorePath, locale); return localized === pathname; }); }