javascript - React Router Redux - Component never renders -
i'm trying latest react-router-redux (v5) working, never renders component. 1 gets rendered home (/). breakpoints in other routes components never hit. i've removed connect(mapstatetoprops, mapdispatchtoprop)(component) call (and did simple component) - still nothing rendered.
the route in browser bar changes. if import projects in index.js, rid of routing , nav, renders fine.
i've copy pasted documentation @
https://github.com/reacttraining/react-router/tree/master/packages/react-router-redux
unless there incompatibility i'm not aware of?
the code
packages.json
"react": "15.5.4", "react-dom": "15.5.4", "history": "^4.6.3", "isomorphic-fetch": "^2.2.1", "prop-types": "^15.5.10", "react-redux": "^5.0.6", "react-router": "^4.1.2", "react-router-redux": "^5.0.0-alpha.6", "redux": "^3.7.2", "redux-logger": "^3.0.6", "redux-thunk": "^2.2.0",
/index.js
import { router, route, indexroute, browserhistory } 'react-router'; import { connectedrouter, routerreducer, routermiddleware, push } 'react-router-redux' import createhistory 'history/createbrowserhistory' import react 'react' import { render } 'react-dom' import { createstore, applymiddleware, combinereducers} 'redux' import { provider } 'react-redux' import thunkmiddleware 'redux-thunk'; import { createlogger } 'redux-logger'; let routes = require('./routes').routes; import reducers './reducers' const history = createhistory(); const routermiddle = routermiddleware(history); const store = createstore( combinereducers({ ...reducers, router: routerreducer }, applymiddleware( routermiddle, thunkmiddleware, createlogger() )) ) render( <provider store={store}> <connectedrouter history={history} > {routes} </connectedrouter> {/* <projects /> <-- works if comment out connectedrouter */} </provider> , document.getelementbyid('react-app') );
/routes.js
import * react 'react'; import { route } 'react-router'; import { layout } './components/layout'; import { home } './components/home'; import { projects } './components/projects'; export const routes = <layout> <route exact path='/' component={ home } /> <route path='projects' component={ projects } /> </layout>;
/components/projects.js
import react, { component } 'react'; import { connect } 'react-redux'; class projects extends component { render() { //debugger; return ( <div>woe me</div> ) } } export default projects;
also, can see actions being dispatched route changes:
i think had similar issue when upgraded react-router v4 , have solved using withrouter
in root component.
export default ( <router history={history} onupdate={logpageview}> <root> <switch> <route exact path="/" component={home} /> <route path="/about" component={about} /> <route path="/calculator" component={calc} /> <route path="/how-it-works" component={howitworks} /> <route path="/get-landed" component={getlanded} /> <route status={404} path="*" component={home} /> </switch> </root> </router> );
if don't have root component try on components of routes.
import { withrouter } 'react-router' class root extends react.component { ... } // create new component "connected" (to borrow redux // terminology) router. export default const rootwithrouter = withrouter(root)
here few other links inspired from:
Comments
Post a Comment