How to do a conditional redirect?
ashep opened this issue · comments
Oleksandr Shepetko commented
Hi there. I need to redirect from one route to another conditionally.
App
:
export default class App extends React.Component {
render(): JSX.Element {
return (
<Router>
<Home path={"/"} needSetup={true} />
<Settings path={"/settings"}/>
</Router>
);
}
}
Home
:
export default class Home extends React.Component {
componentWillMount() {
if (this.props.needSetup) {
console.log("redirecting...");
route("/settings", true);
}
}
render(): JSX.Element {
return (
<React.Fragment/>
);
}
}
I see the "redirecting..." output in the console, but no redirect is happening.
Thank you.
Ryan Christian commented
Looks like a bug, though I'd recommend switching to preact-iso
. preact-router
unfortunately hasn't been maintained.
Oleksandr Shepetko commented
Thank you @rschristian!