reactjs - Is react-router-dom <Redirect /> not working with syncHistoryWithStore? -
i'm trying redirect user sign in page when trying access page requires privileges. basically, /
route requires user logged in redirect them /signin
if they're not.
using react-router-redux's synchistorywithstore, redirect doesn't happen. when remove it, works expected.
is synchistorywithstore incompatible latest version of react-router-dom?
here's reproduction. can uncomment history line not use synchistorywithstore , see works expected.
also embedding code here on stackoverflow.
import react 'react'; import reactdom 'react-dom'; import { provider } 'react-redux'; import { createstore, combinereducers } 'redux'; import { createbrowserhistory } 'history'; import { router, route, redirect } 'react-router-dom'; import { synchistorywithstore, routerreducer } 'react-router-redux'; const store = createstore( combinereducers({ routing: routerreducer }) ); const history = synchistorywithstore(createbrowserhistory(), store); //const history = createbrowserhistory(); function signin(){ return ( <div>this signin.</div> ); } function home(){ return ( <div>this home.</div> ); } const isloggedin = false; reactdom.render( <provider store={store}> <router history={history}> <div> <route exact path="/signin" component={signin} /> <route exact path="/" render={() => isloggedin ? <home /> : <redirect to="/signin" />} /> </div> </router> </provider>, window.document.getelementbyid('root') );
as tharaka pointed out, readme mentions react-router v4 not supported yet.
Comments
Post a Comment