I'm building a React app and using Found as the router.
The docs describe a technique for doing custom redirection.
Here is a code sample of what I'm attempting to accomplish:
class App extends React.Component {
render() {
const { viewer, children } = this.props;
if (viewer === null && this.props.location.pathname != "/login") {
throw new RedirectException({ action: "PUSH", pathname: "/login" });
}
return (
<div>
{children}
</div>
);
}
}
Basically I just want to redirect to the login page if there is no user. When I do this, the address bar correctly updates to /login, but I see an error in the console -
Uncaught (in promise) TypeError: Cannot read property '_currentElement' of null
at ReactCompositeComponentWrapper._updateRenderedComponent (ReactCompositeComponent.js?d2b3:744)
at ReactCompositeComponentWrapper._performComponentUpdate (ReactCompositeComponent.js?d2b3:723)
at ReactCompositeComponentWrapper.updateComponent (ReactCompositeComponent.js?d2b3:644)
at ReactCompositeComponentWrapper.receiveComponent (ReactCompositeComponent.js?d2b3:546)
at Object.receiveComponent (ReactReconciler.js?399b:124)
at ReactCompositeComponentWrapper._updateRenderedComponent (ReactCompositeComponent.js?d2b3:753)
at ReactCompositeComponentWrapper._performComponentUpdate (ReactCompositeComponent.js?d2b3:723)
at ReactCompositeComponentWrapper.updateComponent (ReactCompositeComponent.js?d2b3:644)
at ReactCompositeComponentWrapper.receiveComponent (ReactCompositeComponent.js?d2b3:546)
at Object.receiveComponent (ReactReconciler.js?399b:124)
If I do a page refresh at this point, the login page works just fine.
What am I missing here?
window.location = '/login'