Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
componentDidUpdate(previousProps) {
const existingRoute = previousProps.route.match.url;
const newRoute = this.props.route.match.url;
// don't change state (refetch route data) if the route has not changed
if (existingRoute === newRoute) {
return;
}
// if in experience editor - force reload instead of route data update
// avoids confusing Sitecore's editing JS
if (isExperienceEditorActive()) {
window.location.assign(newRoute);
return;
}
this.updateLanguage();
this.updateRouteData();
}
componentWillReceiveProps(newProps) {
const existingRoute = this.props.route.match.url;
const newRoute = newProps.route.match.url;
if (existingRoute !== newRoute) {
// if in experience editor - force reload
if (isExperienceEditorActive()) {
window.location.assign(newRoute);
return;
}
// get the route data for the new route
SitecoreContentService.getRouteData(newRoute).then((routeData) => {
if (routeData !== null) {
// set the sitecore context data and push the new route
SitecoreContextFactory.setSitecoreContext({
route: routeData.sitecore.route,
itemId: routeData.sitecore.route.itemId,
...routeData.sitecore.context,
});
this.setState({ state: routeData, notFound: false });
} else {
this.setState({ notFound: true });
componentDidUpdate(previousProps) {
const existingRoute = previousProps.route.match.url;
const newRoute = this.props.route.match.url;
// don't change state (refetch route data) if the route has not changed
if (existingRoute === newRoute) {
return;
}
// if in experience editor - force reload instead of route data update
// avoids confusing Sitecore's editing JS
if (isExperienceEditorActive()) {
window.location.assign(newRoute);
return;
}
this.updateLanguage();
this.updateRouteData();
}