Skip to content

Instantly share code, notes, and snippets.

@BrianJenney
Created July 15, 2022 17:58
Show Gist options
  • Save BrianJenney/70e1de92f1bfeadb3bdb9257911540f1 to your computer and use it in GitHub Desktop.
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?
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