Created
July 15, 2022 17:58
-
-
Save BrianJenney/70e1de92f1bfeadb3bdb9257911540f1 to your computer and use it in GitHub Desktop.
This code needs to be reviewed. What are some constructive comments and feedback you could share with the author of this code?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subroutes from '../routes'; | |
import { addTrailingSlashIfNone } from '../utils/helpers'; | |
/* | |
function to determine the redirect route based on the currentLocaion | |
*/ | |
const determineRedirect = (currentLocaion) => { | |
if (subroutes & seoData) { | |
var validAccountPage = false; | |
let orderLandingPage = false; | |
const NewLocation = addTrailingSlashIfNone(currentLocation); | |
if (NewLocation.includes('/account/')) { | |
const accountObject = subroutes.find((element) => element.path === '/account/'); | |
if (accountObject.routes.map((route) => route.path).includes(NewLocation)) { | |
validAccountPage = true; | |
} | |
} | |
if (NewLocation.includes('/orders/') || NewLocation.includes('/landing/')) { | |
orderLandingPage = true; | |
} | |
if ( | |
subroutes.map((route) => route.path).includes(NewLocation) || | |
seoData.map((data) => data.page).includes(NewLocation) || | |
validAccountPage || | |
orderLandingPage | |
) { | |
// do nothing | |
} else { | |
<Redirect to="/not_found/" />; | |
} | |
} | |
} | |
export default determineRedirect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment