react router - Routing Issue In ReactJs -
i beginner in reactjs. trying create multipage app, i'm facing issues related routing.
this code:
import react 'react'; import reactdom 'react-dom'; import { router, route} 'react-router'; ...... reactdom.render(( <router> <route path="/" component={my}> <route path="home" component={home}> <route path="contact" component={contact}/> <route path="about" component={about}/> </route> </route> </router> ), document.getelementbyid('root'))
it seems react router expecting history prop haven't provided. here example router v4 doesn't support route nesting in question example.
import react 'react' import reactdom 'react-dom' import { browserrouter, route, switch } 'react-router-dom' reactdom.render(( <browserrouter> <div classname='app'> <div classname='page'> <switch> <route exact path="/" component={1} /> <route path="/second-page" component={2} /> <route path="/third-page" component={3} /> <route component={errorpage} /> </switch> </div> </div> </browserrouter> ), document.getelementbyid('root'))
this 1 route components per respective paths, or return errorpage component if no routes matched.
edit: history prop useless , ignored in browserhistory, purpose of browserhistory create browserhistory.
from source code :
warning( !this.props.history, '<browserrouter> ignores history prop. use custom history, ' + 'use `import { router }` instead of `import { browserrouter router }`.' )
Comments
Post a Comment