iam new on React and have a Project where i have to implement a react joyride tour into a finished tool.
currently i have this if condition to check on which page iam, to set the right steps.
if (this.props.location.pathname === '/') {
steps = []
} else if (this.props.location.pathname === '/matches/' || this.props.location.pathname === '/matches') {
if (this.props.firstPartClicked === true) {
steps = matchSiteStepsOne
} else if (this.props.secondPartClicked === true) {
steps = matchSiteStepsTwo
} else {
steps = matchSiteSteps
}
} else if (this.props.location.pathname.startsWith('/matches/') && this.props.location.pathname.endsWith('/edit/') && this.props.location.pathname.match('\\d+')) {
if (this.props.firstPartClicked === true) {
steps = matchEditorStepsOne
} else if (this.props.secondPartClicked === true) {
steps = matchEditorStepsTwo
} else {
steps = matchEditorSteps
}
} else if (this.props.location.pathname.startsWith('/matches/') && this.props.location.pathname.includes('sequence')) {
if (this.props.firstPartClicked === true) {
steps = matchSequenceStepsOne
} else if (this.props.secondPartClicked === true) {
steps = matchSequenceStepsTwo
} else {
steps = matchSequenceSteps
}
} else if (this.props.location.pathname.startsWith('/matches/') && this.props.location.pathname.match('\\d+')) {
steps = matchSteps
}
now my question is if is there a way to make it more generic so i can easily expand more steps on different pages, without so much redundant code?
Aucun commentaire:
Enregistrer un commentaire