Observable-based routing
import React from 'react';
import { Router, Route, hashHistory} from 'react-router';
import store from './store';
import Wizard from './Wizard';
// some screens:
import Start from './Start';
import Error from './Error';
import Select from './Select';
class WizardRouter extends React.Component {
// Determines which screen to show on initial load
redirectToDefault = (nextState, replace) => {
if (nextState.location.pathname === '/wizard') {
replace(this.selectRoute() || '/wizard/start');
}
};
// This method is also provided as selectRoute handler to autorun in Wizard.jsx
selectRoute = () => {
switch (store.stage) {
case store.STAGES.error:
return '/wizard/error';
case store.STAGES.select:
return '/wizard/select';
}
return null;
};
render() {
return (
<Router history={hashHistory}>
<Route path="/wizard"
component={Wizard}
onEnter={this.redirectToDefault}
selectRoute={this.selectRoute}
>
<Route path="start" component={Start} />
<Route path="error" component={Error} />
<Route path="select" component={Select} />
</Route>
</Router>
);
}
}
export default WizardRouter;Last updated