javascript - Problems using react-router for basic routing after installing it on a new project -
about 4 days ago, created project react-router
. installed normal, following this guide. installed react-router
via recommended method in official github readme. odd reason, wouldn't render of components until moved route index.js
file in root directory, began work. before, route located inside of app.jsx
file.
today, decided wanted create small portfolio site myself, since feel i'm understanding basics of react. installed did before, w/ versions 3.0.0
, 15.3.2
of react-router
, react / react-dom
respectively. versions have not changed since last project few days back. however, seems react-router
no longer working reason, showing no errors in console, , i've spent hours searching google , stack overflow solutions. code super bare-bones currently, index.js
file looking following, without use of react-router
:
import react 'react' import {render} 'react-dom' class app extends react.component { render() { return <div>{this.props.children}</div>; } } const home = () => <p>hello</p>; render( <app><home /></app>, document.getelementbyid('main'))
i understand should moving towards more functional programming, time being have app
written class, testing reasons. now, why above code work correctly, code snippet below not produce results?
import react 'react' import {render} 'react-dom' import {router, route, indexroute, hashhistory} 'react-router' class app extends react.component { render() { return <div>{this.props.children}</div>; } } const home = () => <p>hello</p>; render( (<router history="hashhistory"> <route path="/" component={app}> <indexroute component={home} /> </route> </router>), document.getelementbyid('main'))
i not think i'm misunderstanding react-router
in way. i've tried wrapping route in ()
, i've seen in tutorials, didn't make difference -- obviously.
is there wrong code? or else? if there more information can provide guys, let me know. can take screen shots or something, if of out.
i think should change
<router history="hashhistory">
to
<router history={hashhistory}>
router expecting history objetct, not string:
var router = _react2.default.createclass({ displayname: 'router', proptypes: { history: object (...) });
Comments
Post a Comment