javascript - React routes doesn't work -


import react, { component } 'react'; import './app.css'; var reactrouter = require('react-router'); var router  = reactrouter.router; var route = reactrouter.route; var navigation = reactrouter.navigation;  var storepicker = react.createclass({ render : function() { return (   <form classname="store-selector">     <h2>please enter store</h2>     </form> ) }  });  var routes = ( <router> <route path="/" component={storepicker}/> <route path="store" component={app}/> </router> ) export default routes; 

i trying work react router. code not working. doesn't gives errors. gives 2 warnings.


warning: failed prop type: prop history marked required in router, value undefined. in router


react.createelement: type invalid -- expected string (for built-in components) or class/function (for composite components) got: object.

for warning:
(warning: failed prop type: prop history marked required in router, value undefined. in router)

you're missing history definition router try:

<router history={hashistory|browserhistory|creatememoryhistory}>   <route path="/" component={home} /> </router>

nb: you'll have add chosen history type imports react router, if choose add browserhistory import this:

import { browserhistory, router, route } 'react-router'            ^---added named import

a brief explanation of different options:

browserhistory : bases path of full url starting route '/'. if spa @ www.myapp.com, root path coorespond www.myapp.com/ default. if wanted route www.myapp.com/blog, need define router path of '/blog'.

hashistory: same thing root starts the first # character found in url: example.com/#/some/path correspond to: /some/path

creatememoryhistory: used testing , server rendering. option not read or manipulate address bar.

check out: react router histories more info


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -